test: fix tests on windows

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
Mark Sagi-Kazar 2024-06-04 15:47:35 +02:00 committed by Márk Sági-Kazár
parent 164252315d
commit d59cc8b6cd
2 changed files with 5 additions and 3 deletions

View File

@ -53,6 +53,8 @@ func (v *Viper) findConfigFileWithFinder(finder Finder) (string, error) {
return "", ConfigFileNotFoundError{v.configName, fmt.Sprintf("%s", v.configPaths)}
}
// We call clean on the final result to ensure that the path is in its canonical form.
// This is mostly for consistent path handling and to make sure tests pass.
return results[0], nil
}

View File

@ -368,10 +368,10 @@ func TestGetConfigFile(t *testing.T) {
t.Run("using a finder", func(t *testing.T) {
fs := afero.NewMemMapFs()
err := fs.Mkdir(testutil.AbsFilePath(t, "/etc/viper"), 0o777)
err := fs.Mkdir("/etc/viper", 0o777)
require.NoError(t, err)
_, err = fs.Create(testutil.AbsFilePath(t, "/etc/viper/config.yaml"))
_, err = fs.Create("/etc/viper/config.yaml")
require.NoError(t, err)
finder := locafero.Finder{
@ -389,7 +389,7 @@ func TestGetConfigFile(t *testing.T) {
v.SetConfigName("not-config")
filename, err := v.getConfigFile()
assert.Equal(t, testutil.AbsFilePath(t, "/etc/viper/config.yaml"), filename)
assert.Equal(t, "/etc/viper/config.yaml", filename)
assert.NoError(t, err)
})
}