From 6fdfebc843512eb25f3b10305839f6f00af68064 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Thu, 14 Sep 2023 13:49:54 +0300 Subject: [PATCH] Fix tests on Windows --- viper_test.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/viper_test.go b/viper_test.go index 688e33c..23f8b14 100644 --- a/viper_test.go +++ b/viper_test.go @@ -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 @@ -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`)) }