MCPcopy
hub / github.com/spf13/viper / TestReadConfig

Function TestReadConfig

viper_test.go:1543–1566  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1541}
1542
1543func TestReadConfig(t *testing.T) {
1544 t.Run("ok", func(t *testing.T) {
1545 v := New()
1546 v.SetConfigType("yaml")
1547 err := v.ReadConfig(bytes.NewBuffer(yamlExample))
1548 require.NoError(t, err)
1549 t.Log(v.AllKeys())
1550
1551 assert.True(t, v.InConfig("name"))
1552 assert.True(t, v.InConfig("clothing.jacket"))
1553 assert.False(t, v.InConfig("state"))
1554 assert.False(t, v.InConfig("clothing.hat"))
1555 assert.Equal(t, "steve", v.Get("name"))
1556 assert.Equal(t, []any{"skateboarding", "snowboarding", "go"}, v.Get("hobbies"))
1557 assert.Equal(t, map[string]any{"jacket": "leather", "trousers": "denim", "pants": map[string]any{"size": "large"}}, v.Get("clothing"))
1558 assert.Equal(t, 35, v.Get("age"))
1559 })
1560
1561 t.Run("missing config type", func(t *testing.T) {
1562 v := New()
1563 err := v.ReadConfig(bytes.NewBuffer(yamlExample))
1564 require.Error(t, err)
1565 })
1566}
1567
1568func TestReadConfigWithSetConfigFile(t *testing.T) {
1569 v := New()

Callers

nothing calls this directly

Calls 7

NewFunction · 0.85
SetConfigTypeMethod · 0.80
ReadConfigMethod · 0.80
AllKeysMethod · 0.80
InConfigMethod · 0.80
GetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected