mirror of
https://github.com/spf13/viper
synced 2025-05-07 20:57:18 +00:00
Added test for index notation in keys
This commit is contained in:
parent
02aa8552a1
commit
a641c3b4e7
1 changed files with 33 additions and 0 deletions
|
@ -1400,6 +1400,39 @@ func TestParseNested(t *testing.T) {
|
||||||
assert.Equal(t, 200*time.Millisecond, items[0].Nested.Delay)
|
assert.Equal(t, 200*time.Millisecond, items[0].Nested.Delay)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetMapSliceItemWithIndex(t *testing.T) {
|
||||||
|
type duration struct {
|
||||||
|
Delay time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
type item struct {
|
||||||
|
Name string
|
||||||
|
Delay time.Duration
|
||||||
|
Nested duration
|
||||||
|
}
|
||||||
|
|
||||||
|
config := `[[parent]]
|
||||||
|
delay="100ms"
|
||||||
|
[parent.nested]
|
||||||
|
delay="200ms"
|
||||||
|
|
||||||
|
[[parent]]
|
||||||
|
delay="200ms"
|
||||||
|
[parent.nested]
|
||||||
|
delay="400ms"
|
||||||
|
`
|
||||||
|
initConfig("toml", config)
|
||||||
|
|
||||||
|
firstNestedDelay := v.GetDuration("parent[0].delay")
|
||||||
|
|
||||||
|
assert.Equal(t, 100*time.Millisecond, firstNestedDelay)
|
||||||
|
|
||||||
|
secondNestedDelay := v.GetDuration("parent[1].nested.delay")
|
||||||
|
|
||||||
|
assert.Equal(t, 400*time.Millisecond, secondNestedDelay)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func doTestCaseInsensitive(t *testing.T, typ, config string) {
|
func doTestCaseInsensitive(t *testing.T, typ, config string) {
|
||||||
initConfig(typ, config)
|
initConfig(typ, config)
|
||||||
Set("RfD", true)
|
Set("RfD", true)
|
||||||
|
|
Loading…
Add table
Reference in a new issue