use absolute path when getting grafana path; add test for directory (#36001)

This commit is contained in:
Kevin Minehart
2021-07-06 11:28:02 -05:00
committed by GitHub
parent 17707d886a
commit 92cb503486
2 changed files with 22 additions and 1 deletions

View File

@@ -29,3 +29,17 @@ func TestExists_Existent(t *testing.T) {
require.True(t, exists)
}
func TestExists_Dir(t *testing.T) {
f, err := ioutil.TempDir("", "")
require.NoError(t, err)
t.Cleanup(func() {
err := os.Remove(f)
assert.NoError(t, err)
})
exists, err := Exists(f)
require.NoError(t, err)
require.True(t, exists)
}

View File

@@ -121,13 +121,20 @@ func CreateGrafDir(t *testing.T, opts ...GrafanaOpts) (string, string) {
found := false
for i := 0; i < 20; i++ {
rootDir = filepath.Join(rootDir, "..")
exists, err := fs.Exists(filepath.Join(rootDir, "public", "views"))
dir, err := filepath.Abs(rootDir)
require.NoError(t, err)
exists, err := fs.Exists(filepath.Join(dir, "public", "views"))
require.NoError(t, err)
if exists {
rootDir = dir
found = true
break
}
}
require.True(t, found, "Couldn't detect project root directory")
cfgDir := filepath.Join(tmpDir, "conf")