SEBRAUC/src/fixtures/testutil.go
Theta-Dev 51eb9c0cac
All checks were successful
continuous-integration/drone/push Build is passing
finished uploader component
2021-11-21 01:31:38 +01:00

41 lines
622 B
Go

package fixtures
import (
"os"
"path/filepath"
)
func doesFileExist(filepath string) bool {
_, err := os.Stat(filepath)
return !os.IsNotExist(err)
}
func getProjectRoot() string {
p, err := os.Getwd()
if err != nil {
panic(err)
}
for i := 0; i < 10; i++ {
if doesFileExist(filepath.Join(p, "go.mod")) {
return p
}
p = filepath.Join(p, "..")
}
panic("Could not find project root")
}
func CdProjectRoot() {
root := getProjectRoot()
err := os.Chdir(root)
if err != nil {
panic(err)
}
}
func GetTestfilesDir() string {
CdProjectRoot()
return filepath.Join("src", "fixtures", "testfiles")
}