From a77201a9f066c620b096914b8710d63ac7d853c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lovro=20Ma=C5=BEgon?= Date: Wed, 17 Apr 2024 18:42:29 +0200 Subject: [PATCH] don't populate empty defaults (#39) --- config/config.go | 2 +- config/config_test.go | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) 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", }, }}