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

Function TestUnmarshaling

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

Source from the content-addressed store, hash-verified

482}
483
484func TestUnmarshaling(t *testing.T) {
485 v := New()
486 v.SetConfigType("yaml")
487 r := bytes.NewReader(yamlExample)
488
489 v.unmarshalReader(r, v.config)
490 assert.True(t, v.InConfig("name"))
491 assert.True(t, v.InConfig("clothing.jacket"))
492 assert.False(t, v.InConfig("state"))
493 assert.False(t, v.InConfig("clothing.hat"))
494 assert.Equal(t, "steve", v.Get("name"))
495 assert.Equal(t, []any{"skateboarding", "snowboarding", "go"}, v.Get("hobbies"))
496 assert.Equal(t, map[string]any{"jacket": "leather", "trousers": "denim", "pants": map[string]any{"size": "large"}}, v.Get("clothing"))
497 assert.Equal(t, 35, v.Get("age"))
498}
499
500func TestUnmarshalExact(t *testing.T) {
501 v := New()

Callers

nothing calls this directly

Calls 5

NewFunction · 0.85
SetConfigTypeMethod · 0.80
unmarshalReaderMethod · 0.80
InConfigMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected