Add test for top level keys

This commit is contained in:
Matt Spaulding 2016-11-07 17:06:05 +00:00
parent 4c6d781515
commit 6816bca321
1 changed files with 46 additions and 0 deletions

View File

@ -44,6 +44,23 @@ var yamlExampleWithExtras = []byte(`Existing: true
Bogus: true
`)
var yamlTopLevelKeys = []byte(`
restuarants:
types:
sushi:
name: sushi2go
rating: 10
price: average
italian:
name: "pizza place"
rating: 7
price: average
thai:
name: "thai garden"
rating: 9
price: high
`)
type testUnmarshalExtra struct {
Existing bool
}
@ -462,6 +479,35 @@ func TestAllKeysWithEnv(t *testing.T) {
assert.Equal(t, expectedKeys, keys)
}
func TestTopLevelKeys(t *testing.T) {
v := New()
v.SetConfigType("yaml")
r := bytes.NewReader(yamlTopLevelKeys)
err := v.ReadConfig(r)
assert.NoError(t, err)
fmt.Printf("%#v\n", v.config)
s := v.Sub("restuarants.types")
for _, i := range s.TopLevelKeys() {
ss := s.Sub(i)
switch i {
case "sushi":
assert.Equal(t, ss.GetString("name"), "sushi2go")
assert.Equal(t, ss.GetString("price"), "average")
assert.Equal(t, ss.GetInt("rating"), 10)
case "italian":
assert.Equal(t, ss.GetString("name"), "pizza place")
assert.Equal(t, ss.GetString("price"), "average")
assert.Equal(t, ss.GetInt("rating"), 7)
case "thai":
assert.Equal(t, ss.GetString("name"), "thai garden")
assert.Equal(t, ss.GetString("price"), "high")
assert.Equal(t, ss.GetInt("rating"), 9)
default:
t.Fatalf("unexpected key, %q", i)
}
}
}
func TestAliasesOfAliases(t *testing.T) {
Set("Title", "Checking Case")
RegisterAlias("Foo", "Bar")