Skip to content

Commit

Permalink
Fix tests on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear authored and sagikazarmark committed Sep 16, 2023
1 parent 4aeec58 commit 6fdfebc
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions viper_test.go
Expand Up @@ -248,18 +248,16 @@ func initDirs(t *testing.T) (string, string) {

root := t.TempDir()

err := os.Chdir(root)
require.Nil(t, err)

for _, dir := range testDirs {
err = os.Mkdir(dir, 0o750)
assert.Nil(t, err)
innerDir := filepath.Join(root, dir)
err := os.Mkdir(innerDir, 0o750)
require.NoError(t, err)

err = os.WriteFile(
path.Join(dir, config+".toml"),
[]byte("key = \"value is "+dir+"\"\n"),
filepath.Join(innerDir, config+".toml"),
[]byte(`key = "value is `+dir+`"`+"\n"),
0o640)
assert.Nil(t, err)
require.NoError(t, err)
}

return root, config
Expand Down Expand Up @@ -1506,15 +1504,15 @@ func TestDirsSearch(t *testing.T) {
v.SetDefault(`key`, `default`)

entries, err := os.ReadDir(root)
assert.Nil(t, err)
require.NoError(t, err)
for _, e := range entries {
if e.IsDir() {
v.AddConfigPath(e.Name())
v.AddConfigPath(filepath.Join(root, e.Name()))
}
}

err = v.ReadInConfig()
assert.Nil(t, err)
require.NoError(t, err)

assert.Equal(t, `value is `+filepath.Base(v.configPaths[0]), v.GetString(`key`))
}
Expand Down

0 comments on commit 6fdfebc

Please sign in to comment.