Skip to content

Commit 709c7da

Browse files
- Added error check for value as empty in case of empty value
- Fixed unit tests
1 parent 8e1f829 commit 709c7da

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

internal/commands/root.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,9 @@ func extractOptionalFlags(cmd *cobra.Command) error {
461461
if len(keyVal) != params.KeyValuePairSize {
462462
return errors.New("Invalid optional flags. Optional flags should be in a KEY1=VALUE1;KEY2=VALUE2 format")
463463
}
464+
if strings.TrimSpace(keyVal[1]) == "" {
465+
return errors.New("Invalid optional flags. Value for key " + keyVal[0] + " is empty")
466+
}
464467
err := utils.SetOptionalParam(keyVal[0], keyVal[1])
465468
if err != nil {
466469
return err

internal/wrappers/utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func SetOptionalParam(key, value string) error {
5454
if _, ok := allowedOptionalKeys[key]; ok {
5555
optionalParams[key] = value
5656
} else {
57-
return errors.New("Invalid optional parameter key: " + key)
57+
return errors.New("Invalid optional flags parameter key: " + key)
5858
}
5959
return nil
6060
}

internal/wrappers/utils/utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func TestSetNotAllowedKeyDoesNotSet(t *testing.T) {
198198
value := "value"
199199

200200
err := SetOptionalParam(key, value)
201-
assert.Nil(t, err)
201+
assert.NotNil(t, err)
202202

203203
if hasOptionalParam(key) {
204204
t.Fatalf("expected hasOptionalParam(%q) to be false for disallowed key", key)

0 commit comments

Comments
 (0)