From 237b7040d9b0d3c8665286df17dd7905e67b70f1 Mon Sep 17 00:00:00 2001 From: Miguel Eduardo Gil Biraud Date: Sat, 21 Jan 2017 01:51:27 +0100 Subject: [PATCH] Failing test for key unmarshaling with nested structs containing time.Duration --- viper_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/viper_test.go b/viper_test.go index cd7b65c..cd10603 100644 --- a/viper_test.go +++ b/viper_test.go @@ -1102,6 +1102,35 @@ func TestCaseInsensitiveSet(t *testing.T) { } } +func TestParseNested(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" +` + initConfig("toml", config) + + var items []item + err := v.UnmarshalKey("parent", &items) + if err != nil { + t.Fatalf("unable to decode into struct, %v", err) + } + + assert.Equal(t, 1, len(items)) + assert.Equal(t, 100*time.Millisecond, items[0].Delay) + assert.Equal(t, 200*time.Millisecond, items[0].Nested.Delay) +} + func doTestCaseInsensitive(t *testing.T, typ, config string) { initConfig(typ, config) Set("RfD", true)