Cleaned code for project root retrieval

main
oabrivard 2 years ago
parent f2ddc28884
commit cd2d008166

@ -3,18 +3,10 @@ package file
import ( import (
"os" "os"
"path/filepath" "path/filepath"
"runtime"
) )
var ( // ProjectRoot returns the root folder of the project
_, b, _, _ = runtime.Caller(0) func ProjectRoot() string {
// Root folder of this project
ProjectRoot = filepath.Join(filepath.Dir(b), "..")
)
// GetBasePath returns the root folder of the project
func GetBasePath() string {
dir, err := os.Getwd() dir, err := os.Getwd()
if err != nil { if err != nil {
panic(err) panic(err)

@ -5,15 +5,9 @@ import (
"testing" "testing"
) )
func TestProjectRoot(t *testing.T) {
if !strings.Contains(ProjectRoot, "abrolgo") {
t.Errorf("ProjectRoot is not correct: %s", ProjectRoot)
}
}
func TestGetBasePath(t *testing.T) { func TestGetBasePath(t *testing.T) {
basePath := GetBasePath() basePath := ProjectRoot()
if !strings.Contains(basePath, "abrolgo") { if !strings.Contains(basePath, "abrolgo") {
t.Errorf("GetBasePath is not correct: %s", basePath) t.Errorf("ProjectRoot is not correct: %s", basePath)
} }
} }

Loading…
Cancel
Save