mirror of
https://github.com/spf13/viper
synced 2024-12-22 19:47:01 +00:00
test: refactor read config test
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
parent
3266e43d90
commit
e8707fde20
1 changed files with 16 additions and 13 deletions
|
@ -1641,20 +1641,23 @@ func TestFindsNestedKeys(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadBufConfig(t *testing.T) {
|
func TestReadConfig(t *testing.T) {
|
||||||
v := New()
|
t.Run("ok", func(t *testing.T) {
|
||||||
v.SetConfigType("yaml")
|
v := New()
|
||||||
v.ReadConfig(bytes.NewBuffer(yamlExample))
|
v.SetConfigType("yaml")
|
||||||
t.Log(v.AllKeys())
|
err := v.ReadConfig(bytes.NewBuffer(yamlExample))
|
||||||
|
require.NoError(t, err)
|
||||||
|
t.Log(v.AllKeys())
|
||||||
|
|
||||||
assert.True(t, v.InConfig("name"))
|
assert.True(t, v.InConfig("name"))
|
||||||
assert.True(t, v.InConfig("clothing.jacket"))
|
assert.True(t, v.InConfig("clothing.jacket"))
|
||||||
assert.False(t, v.InConfig("state"))
|
assert.False(t, v.InConfig("state"))
|
||||||
assert.False(t, v.InConfig("clothing.hat"))
|
assert.False(t, v.InConfig("clothing.hat"))
|
||||||
assert.Equal(t, "steve", v.Get("name"))
|
assert.Equal(t, "steve", v.Get("name"))
|
||||||
assert.Equal(t, []any{"skateboarding", "snowboarding", "go"}, v.Get("hobbies"))
|
assert.Equal(t, []any{"skateboarding", "snowboarding", "go"}, v.Get("hobbies"))
|
||||||
assert.Equal(t, map[string]any{"jacket": "leather", "trousers": "denim", "pants": map[string]any{"size": "large"}}, v.Get("clothing"))
|
assert.Equal(t, map[string]any{"jacket": "leather", "trousers": "denim", "pants": map[string]any{"size": "large"}}, v.Get("clothing"))
|
||||||
assert.Equal(t, 35, v.Get("age"))
|
assert.Equal(t, 35, v.Get("age"))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsSet(t *testing.T) {
|
func TestIsSet(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue