mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-12 06:24:10 +01:00
config: handle empty configurations
This commit is contained in:
@@ -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())
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user