mirror of
https://github.com/spf13/viper
synced 2024-12-22 19:47:01 +00:00
test: add tests for experimental finder
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
parent
92e330ea77
commit
676d2eb166
1 changed files with 46 additions and 1 deletions
|
@ -365,7 +365,27 @@ func TestGetConfigFile(t *testing.T) {
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("using a finder", func(t *testing.T) {
|
t.Run("experimental finder", func(t *testing.T) {
|
||||||
|
fs := afero.NewMemMapFs()
|
||||||
|
|
||||||
|
err := fs.Mkdir(testutil.AbsFilePath(t, "/etc/viper"), 0o777)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
_, err = fs.Create(testutil.AbsFilePath(t, "/etc/viper/config.yaml"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
v := NewWithOptions(ExperimentalFinder())
|
||||||
|
|
||||||
|
v.SetFs(fs)
|
||||||
|
|
||||||
|
v.AddConfigPath("/etc/viper")
|
||||||
|
|
||||||
|
filename, err := v.getConfigFile()
|
||||||
|
assert.Equal(t, testutil.AbsFilePath(t, "/etc/viper/config.yaml"), testutil.AbsFilePath(t, filename))
|
||||||
|
assert.NoError(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("finder", func(t *testing.T) {
|
||||||
fs := afero.NewMemMapFs()
|
fs := afero.NewMemMapFs()
|
||||||
|
|
||||||
err := fs.Mkdir(testutil.AbsFilePath(t, "/etc/viper"), 0o777)
|
err := fs.Mkdir(testutil.AbsFilePath(t, "/etc/viper"), 0o777)
|
||||||
|
@ -445,6 +465,31 @@ func TestReadInConfig(t *testing.T) {
|
||||||
assert.Equal(t, "value", v.Get("key"))
|
assert.Equal(t, "value", v.Get("key"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("find file with experimental finder", func(t *testing.T) {
|
||||||
|
fs := afero.NewMemMapFs()
|
||||||
|
|
||||||
|
err := fs.Mkdir(testutil.AbsFilePath(t, "/etc/viper"), 0o777)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
file, err := fs.Create(testutil.AbsFilePath(t, "/etc/viper/config.yaml"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
_, err = file.WriteString(`key: value`)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
file.Close()
|
||||||
|
|
||||||
|
v := NewWithOptions(ExperimentalFinder())
|
||||||
|
|
||||||
|
v.SetFs(fs)
|
||||||
|
v.AddConfigPath("/etc/viper")
|
||||||
|
|
||||||
|
err = v.ReadInConfig()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
assert.Equal(t, "value", v.Get("key"))
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("find file using a finder", func(t *testing.T) {
|
t.Run("find file using a finder", func(t *testing.T) {
|
||||||
fs := afero.NewMemMapFs()
|
fs := afero.NewMemMapFs()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue