Skip to content

Commit

Permalink
don't populate empty defaults (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
lovromazgon authored Apr 17, 2024
1 parent d2dee0e commit a77201a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
4 changes: 1 addition & 3 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
},
}}
Expand Down

0 comments on commit a77201a

Please sign in to comment.