diff --git a/config/envs.go b/config/envs.go index 512a64e9..76df79fb 100644 --- a/config/envs.go +++ b/config/envs.go @@ -131,18 +131,12 @@ func SetEnv(key, value string) (err error) { return err } -//nolint:dupl func setEnv(node *yaml.Node, key, value string) (persist bool, err error) { // check if key is empty if key == "" { return false, errors.New("key cannot be empty") } - // check if value is empty - if value == "" { - return false, errors.New("value cannot be empty") - } - // find env node keys := []nodeutils.Key{ {Name: KeyClientOptions, Type: yaml.MappingNode}, @@ -160,7 +154,8 @@ func setEnv(node *yaml.Node, key, value string) (persist bool, err error) { } // add or update the envs map per specified key value pair - if len(envs) == 0 || envs[key] != value { + // value could be empty string + if len(envs) == 0 || envs[key] != value || value == "" { envs[key] = value persist = true } diff --git a/config/envs_test.go b/config/envs_test.go index 06857f25..738bc96b 100644 --- a/config/envs_test.go +++ b/config/envs_test.go @@ -63,7 +63,8 @@ func TestGetEnv(t *testing.T) { tests := []struct { name string in *configtypes.ClientConfig - out string + getEnvInput string + getEnvOutput string errStr string errStrForInput string }{ @@ -76,7 +77,8 @@ func TestGetEnv(t *testing.T) { }, }, }, - out: "test", + getEnvInput: "test", + getEnvOutput: "test", }, { name: "get options with empty key", @@ -87,8 +89,9 @@ func TestGetEnv(t *testing.T) { }, }, }, - out: "", - errStr: "key cannot be empty", + getEnvInput: "", + getEnvOutput: "", + errStr: "key cannot be empty", }, { name: "store options with empty key", @@ -99,7 +102,8 @@ func TestGetEnv(t *testing.T) { }, }, }, - out: "", + getEnvInput: "", + getEnvOutput: "", errStr: "key cannot be empty", errStrForInput: "key cannot be empty", }, @@ -112,9 +116,8 @@ func TestGetEnv(t *testing.T) { }, }, }, - out: "test-empty-val", - errStr: "not found", - errStrForInput: "value cannot be empty", + getEnvInput: "test-empty-val", + getEnvOutput: "", }, } for _, spec := range tests { @@ -126,12 +129,12 @@ func TestGetEnv(t *testing.T) { assert.NoError(t, err) } - c, err := GetEnv(spec.out) + c, err := GetEnv(spec.getEnvInput) if spec.errStr != "" { assert.Equal(t, spec.errStr, err.Error()) } else { assert.NoError(t, err) - assert.Equal(t, spec.out, c) + assert.Equal(t, spec.getEnvOutput, c) } }) } diff --git a/config/metadata_settings_api.go b/config/metadata_settings_api.go index 9c77bc6c..787a709a 100644 --- a/config/metadata_settings_api.go +++ b/config/metadata_settings_api.go @@ -160,7 +160,6 @@ func deleteSetting(node *yaml.Node, key string) (err error) { return nil } -//nolint:dupl func setSetting(node *yaml.Node, key, value string) (persist bool, err error) { // check if key is empty if key == "" {