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

Function TestSub

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

Source from the content-addressed store, hash-verified

1689}
1690
1691func TestSub(t *testing.T) {
1692 v := New()
1693 v.SetConfigType("yaml")
1694 v.ReadConfig(bytes.NewBuffer(yamlExample))
1695
1696 subv := v.Sub("clothing")
1697 assert.Equal(t, v.Get("clothing.pants.size"), subv.Get("pants.size"))
1698
1699 subv = v.Sub("clothing.pants")
1700 assert.Equal(t, v.Get("clothing.pants.size"), subv.Get("size"))
1701
1702 subv = v.Sub("clothing.pants.size")
1703 assert.Equal(t, (*Viper)(nil), subv)
1704
1705 subv = v.Sub("missing.key")
1706 assert.Equal(t, (*Viper)(nil), subv)
1707
1708 subv = v.Sub("clothing")
1709 assert.Equal(t, []string{"clothing"}, subv.parents)
1710
1711 subv = v.Sub("clothing").Sub("pants")
1712 assert.Equal(t, []string{"clothing", "pants"}, subv.parents)
1713}
1714
1715func TestSubWithKeyDelimiter(t *testing.T) {
1716 v := NewWithOptions(KeyDelimiter("::"))

Callers

nothing calls this directly

Calls 5

NewFunction · 0.85
SetConfigTypeMethod · 0.80
ReadConfigMethod · 0.80
SubMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected