diff --git a/pkg/infra/fs/exists_test.go b/pkg/infra/fs/exists_test.go index 28b10431e5e..6d2ab13ced8 100644 --- a/pkg/infra/fs/exists_test.go +++ b/pkg/infra/fs/exists_test.go @@ -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) +} diff --git a/pkg/tests/testinfra/testinfra.go b/pkg/tests/testinfra/testinfra.go index aa79c782c5c..ca01c4bcb25 100644 --- a/pkg/tests/testinfra/testinfra.go +++ b/pkg/tests/testinfra/testinfra.go @@ -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")