mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 12:58:02 +08:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user