refactor(test): move image utils for tests in a separate module (#1789)

Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com>
This commit is contained in:
LaurentiuNiculae
2023-09-15 19:53:15 +03:00
committed by GitHub
parent 14206dd6f3
commit 8e18917b07
36 changed files with 1415 additions and 1564 deletions
+27
View File
@@ -1,11 +1,16 @@
package common
import (
"errors"
"net/url"
"os"
"path/filepath"
"gopkg.in/resty.v1"
)
var ErrNoGoModFileFound = errors.New("test: no go.mod file found in parent directories")
func Location(baseURL string, resp *resty.Response) string {
// For some API responses, the Location header is set and is supposed to
// indicate an opaque value. However, it is not clear if this value is an
@@ -23,3 +28,25 @@ func Location(baseURL string, resp *resty.Response) string {
return baseURL + path
}
func GetProjectRootDir() (string, error) {
workDir, err := os.Getwd()
if err != nil {
return "", err
}
for {
goModPath := filepath.Join(workDir, "go.mod")
_, err := os.Stat(goModPath)
if err == nil {
return workDir, nil
}
if workDir == filepath.Dir(workDir) {
return "", ErrNoGoModFileFound
}
workDir = filepath.Dir(workDir)
}
}