From cd2d008166697f76fffa72b298ffd9616aafc195 Mon Sep 17 00:00:00 2001 From: oabrivard Date: Fri, 12 Apr 2024 10:17:20 +0200 Subject: [PATCH] Cleaned code for project root retrieval --- file/file.go | 12 ++---------- file/file_test.go | 10 ++-------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/file/file.go b/file/file.go index 3dbaddb..adecfbe 100644 --- a/file/file.go +++ b/file/file.go @@ -3,18 +3,10 @@ package file import ( "os" "path/filepath" - "runtime" ) -var ( - _, b, _, _ = runtime.Caller(0) - - // Root folder of this project - ProjectRoot = filepath.Join(filepath.Dir(b), "..") -) - -// GetBasePath returns the root folder of the project -func GetBasePath() string { +// ProjectRoot returns the root folder of the project +func ProjectRoot() string { dir, err := os.Getwd() if err != nil { panic(err) diff --git a/file/file_test.go b/file/file_test.go index bb6d84a..b10fdfa 100644 --- a/file/file_test.go +++ b/file/file_test.go @@ -5,15 +5,9 @@ import ( "testing" ) -func TestProjectRoot(t *testing.T) { - if !strings.Contains(ProjectRoot, "abrolgo") { - t.Errorf("ProjectRoot is not correct: %s", ProjectRoot) - } -} - func TestGetBasePath(t *testing.T) { - basePath := GetBasePath() + basePath := ProjectRoot() if !strings.Contains(basePath, "abrolgo") { - t.Errorf("GetBasePath is not correct: %s", basePath) + t.Errorf("ProjectRoot is not correct: %s", basePath) } }