mirror of https://github.com/spf13/viper.git
Fix tests on Windows
This commit is contained in:
parent
4aeec5882c
commit
6fdfebc843
|
@ -248,18 +248,16 @@ func initDirs(t *testing.T) (string, string) {
|
||||||
|
|
||||||
root := t.TempDir()
|
root := t.TempDir()
|
||||||
|
|
||||||
err := os.Chdir(root)
|
|
||||||
require.Nil(t, err)
|
|
||||||
|
|
||||||
for _, dir := range testDirs {
|
for _, dir := range testDirs {
|
||||||
err = os.Mkdir(dir, 0o750)
|
innerDir := filepath.Join(root, dir)
|
||||||
assert.Nil(t, err)
|
err := os.Mkdir(innerDir, 0o750)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = os.WriteFile(
|
err = os.WriteFile(
|
||||||
path.Join(dir, config+".toml"),
|
filepath.Join(innerDir, config+".toml"),
|
||||||
[]byte("key = \"value is "+dir+"\"\n"),
|
[]byte(`key = "value is `+dir+`"`+"\n"),
|
||||||
0o640)
|
0o640)
|
||||||
assert.Nil(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return root, config
|
return root, config
|
||||||
|
@ -1506,15 +1504,15 @@ func TestDirsSearch(t *testing.T) {
|
||||||
v.SetDefault(`key`, `default`)
|
v.SetDefault(`key`, `default`)
|
||||||
|
|
||||||
entries, err := os.ReadDir(root)
|
entries, err := os.ReadDir(root)
|
||||||
assert.Nil(t, err)
|
require.NoError(t, err)
|
||||||
for _, e := range entries {
|
for _, e := range entries {
|
||||||
if e.IsDir() {
|
if e.IsDir() {
|
||||||
v.AddConfigPath(e.Name())
|
v.AddConfigPath(filepath.Join(root, e.Name()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = v.ReadInConfig()
|
err = v.ReadInConfig()
|
||||||
assert.Nil(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, `value is `+filepath.Base(v.configPaths[0]), v.GetString(`key`))
|
assert.Equal(t, `value is `+filepath.Base(v.configPaths[0]), v.GetString(`key`))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue