diff --git a/cmd/config.go b/cmd/config.go index d5c85d8b..44ccf5ae 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -188,7 +188,12 @@ func DefaultHook() (mapstructure.DecodeHookFunc, func()) { // We already have a pointer method, ok := to.Type().MethodByName("Reset") if !ok { - return from.Interface(), nil + // We may have a pointer to a pointer when totally empty. + to = to.Elem() + method, ok = to.Type().MethodByName("Reset") + if !ok { + return from.Interface(), nil + } } if to.IsNil() { new := reflect.New(to.Type().Elem()) diff --git a/cmd/config_test.go b/cmd/config_test.go index b2adc416..0d45a57b 100644 --- a/cmd/config_test.go +++ b/cmd/config_test.go @@ -427,3 +427,36 @@ modules: }) }) } + +func TestDevNullDefault(t *testing.T) { + c := cmd.ConfigRelatedOptions{ + Path: "/dev/null", + Dump: true, + } + + var parsed dummyConfiguration + out := bytes.NewBuffer([]byte{}) + if err := c.Parse(out, "dummy", &parsed); err != nil { + t.Fatalf("Parse() error:\n%+v", err) + } + // Expected configuration + expected := dummyConfiguration{ + Module1: dummyModule1Configuration{ + Listen: "127.0.0.1:8080", + Topic: "nothingness", + Workers: 100, + }, + Module2: dummyModule2Configuration{ + MoreDetails: MoreDetails{ + Stuff: "hello", + }, + Details: dummyModule2DetailsConfiguration{ + Workers: 1, + IntervalValue: time.Minute, + }, + }, + } + if diff := helpers.Diff(parsed, expected); diff != "" { + t.Errorf("Parse() (-got, +want):\n%s", diff) + } +}