forked from mirror/viper
Added test coverage for searching for deeply nested values
This commit is contained in:
parent
b22fa2b439
commit
47b5435941
|
@ -453,3 +453,87 @@ func TestSizeInBytes(t *testing.T) {
|
|||
assert.Equal(t, expected, parseSizeInBytes(str), str)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindsNestedKeys(t *testing.T) {
|
||||
initConfigs()
|
||||
dob, _ := time.Parse(time.RFC3339, "1979-05-27T07:32:00Z")
|
||||
|
||||
Set("super", map[string]interface{}{
|
||||
"deep": map[string]interface{}{
|
||||
"nested": "value",
|
||||
},
|
||||
})
|
||||
|
||||
expected := map[string]interface{}{
|
||||
"super": map[string]interface{}{
|
||||
"deep": map[string]interface{}{
|
||||
"nested": "value",
|
||||
},
|
||||
},
|
||||
"super.deep": map[string]interface{}{
|
||||
"nested": "value",
|
||||
},
|
||||
"super.deep.nested": "value",
|
||||
"owner.organization": "MongoDB",
|
||||
"batters.batter": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "Regular",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"type": "Chocolate",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"type": "Blueberry",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"type": "Devil's Food",
|
||||
},
|
||||
},
|
||||
"hobbies": []interface{}{
|
||||
"skateboarding", "snowboarding", "go",
|
||||
},
|
||||
"title": "TOML Example",
|
||||
"newkey": "remote",
|
||||
"batters": map[string]interface{}{
|
||||
"batter": []interface{}{
|
||||
map[string]interface{}{
|
||||
"type": "Regular",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"type": "Chocolate",
|
||||
}, map[string]interface{}{
|
||||
"type": "Blueberry",
|
||||
}, map[string]interface{}{
|
||||
"type": "Devil's Food",
|
||||
},
|
||||
},
|
||||
},
|
||||
"eyes": "brown",
|
||||
"age": 35,
|
||||
"owner": map[string]interface{}{
|
||||
"organization": "MongoDB",
|
||||
"Bio": "MongoDB Chief Developer Advocate & Hacker at Large",
|
||||
"dob": dob,
|
||||
},
|
||||
"owner.Bio": "MongoDB Chief Developer Advocate & Hacker at Large",
|
||||
"type": "donut",
|
||||
"id": "0001",
|
||||
"name": "Cake",
|
||||
"hacker": true,
|
||||
"ppu": 0.55,
|
||||
"clothing": map[interface{}]interface{}{
|
||||
"jacket": "leather",
|
||||
"trousers": "denim",
|
||||
},
|
||||
"clothing.jacket": "leather",
|
||||
"clothing.trousers": "denim",
|
||||
"owner.dob": dob,
|
||||
"beard": true,
|
||||
}
|
||||
|
||||
for key, expectedValue := range expected {
|
||||
|
||||
assert.Equal(t, expectedValue, v.Get(key))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue