diff --git a/config/config.go b/config/config.go index 06763c7..2aa4c4d 100644 --- a/config/config.go +++ b/config/config.go @@ -51,7 +51,7 @@ func (c Config) Sanitize() Config { func (c Config) ApplyDefaults(params Parameters) Config { for key, param := range params { for _, key := range c.getKeysForParameter(key) { - if strings.TrimSpace(c[key]) == "" { + if strings.TrimSpace(c[key]) == "" && param.Default != "" { c[key] = param.Default } } diff --git a/config/config_test.go b/config/config_test.go index b554591..c6130f7 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -621,7 +621,7 @@ func TestConfig_ApplyDefaults(t *testing.T) { want: Config{ "limit": "-1", "foo.0.param1": "custom", - "foo.0.param2": "", + // empty defaults are not populated }, }, { name: "multiple dynamic params", @@ -634,11 +634,9 @@ func TestConfig_ApplyDefaults(t *testing.T) { want: Config{ "limit": "-1", "foo.0.param1": "parameter", - "foo.0.param2": "", "foo.1.param1": "foo", "foo.1.param2": "custom", "foo.2.param1": "foo", - "foo.2.param2": "", "foo.2.does-not-exist": "unrecognized key still triggers creation of defaults", }, }}