Cleaned code for project root retrieval

main
oabrivard 2 years ago
parent f2ddc28884
commit cd2d008166

@ -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)

@ -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)
}
}

Loading…
Cancel
Save