From 01a29d1e5a10e66eed89aff0a42d5ebebc1bcdbe Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Wed, 10 Sep 2025 11:13:14 -0600 Subject: [PATCH 1/2] CDI-580: Support Case-Insensitive Keys in 'Config' Commands - Update 'set' and 'unset' subcommands to change actual keys, not the user provided case-insensitive keys. --- internal/commands/config/set_internal.go | 6 +++--- internal/commands/config/set_internal_test.go | 11 ++++++++++ internal/commands/config/unset_internal.go | 6 +++--- .../commands/config/unset_internal_test.go | 21 +++++++++++++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/internal/commands/config/set_internal.go b/internal/commands/config/set_internal.go index 7a1bd464..92bde15b 100644 --- a/internal/commands/config/set_internal.go +++ b/internal/commands/config/set_internal.go @@ -39,7 +39,7 @@ func RunInternalConfigSet(kvPair string) (err error) { return fmt.Errorf("failed to set configuration: %w", err) } - if err = setValue(subKoanf, vKey, vValue, opt.Type); err != nil { + if err = setValue(subKoanf, opt.KoanfKey, vValue, opt.Type); err != nil { return fmt.Errorf("failed to set configuration: %w", err) } @@ -60,9 +60,9 @@ func RunInternalConfigSet(kvPair string) (err error) { } if opt.Sensitive && strings.EqualFold(unmaskOptionVal, "false") { - msgStr += fmt.Sprintf("%s=%s", vKey, profiles.MaskValue(vVal)) + msgStr += fmt.Sprintf("%s=%s", opt.KoanfKey, profiles.MaskValue(vVal)) } else { - msgStr += fmt.Sprintf("%s=%s", vKey, vVal) + msgStr += fmt.Sprintf("%s=%s", opt.KoanfKey, vVal) } output.Success(msgStr, nil) diff --git a/internal/commands/config/set_internal_test.go b/internal/commands/config/set_internal_test.go index b185d680..aee0517f 100644 --- a/internal/commands/config/set_internal_test.go +++ b/internal/commands/config/set_internal_test.go @@ -7,6 +7,7 @@ import ( "github.com/pingidentity/pingcli/internal/configuration/options" "github.com/pingidentity/pingcli/internal/customtypes" + "github.com/pingidentity/pingcli/internal/profiles" "github.com/pingidentity/pingcli/internal/testing/testutils" "github.com/pingidentity/pingcli/internal/testing/testutils_koanf" ) @@ -129,4 +130,14 @@ func Test_RunInternalConfigSet_CaseInsensitiveKeys(t *testing.T) { if err != nil { t.Errorf("RunInternalConfigSet returned error: %v", err) } + + //Make sure the actual correct key was set, not the case-insensitive one + vVal, err := profiles.GetOptionValue(options.RootColorOption) + if err != nil { + t.Errorf("GetOptionValue returned error: %v", err) + } + + if vVal != "true" { + t.Errorf("Expected %s to be true, got %v", options.RootColorOption.KoanfKey, vVal) + } } diff --git a/internal/commands/config/unset_internal.go b/internal/commands/config/unset_internal.go index 374f4d0b..3e9c06fc 100644 --- a/internal/commands/config/unset_internal.go +++ b/internal/commands/config/unset_internal.go @@ -32,7 +32,7 @@ func RunInternalConfigUnset(koanfKey string) (err error) { return fmt.Errorf("failed to unset configuration: %w", err) } - err = subKoanf.Set(koanfKey, opt.DefaultValue) + err = subKoanf.Set(opt.KoanfKey, opt.DefaultValue) if err != nil { return fmt.Errorf("failed to unset configuration: %w", err) } @@ -54,9 +54,9 @@ func RunInternalConfigUnset(koanfKey string) (err error) { } if opt.Sensitive && strings.EqualFold(unmaskOptionVal, "false") { - msgStr += fmt.Sprintf("%s=%s", koanfKey, profiles.MaskValue(vVal)) + msgStr += fmt.Sprintf("%s=%s", opt.KoanfKey, profiles.MaskValue(vVal)) } else { - msgStr += fmt.Sprintf("%s=%s", koanfKey, vVal) + msgStr += fmt.Sprintf("%s=%s", opt.KoanfKey, vVal) } output.Success(msgStr, nil) diff --git a/internal/commands/config/unset_internal_test.go b/internal/commands/config/unset_internal_test.go index 1a793788..22d0d4c7 100644 --- a/internal/commands/config/unset_internal_test.go +++ b/internal/commands/config/unset_internal_test.go @@ -7,6 +7,7 @@ import ( "github.com/pingidentity/pingcli/internal/configuration/options" "github.com/pingidentity/pingcli/internal/customtypes" + "github.com/pingidentity/pingcli/internal/profiles" "github.com/pingidentity/pingcli/internal/testing/testutils" "github.com/pingidentity/pingcli/internal/testing/testutils_koanf" ) @@ -62,3 +63,23 @@ func Test_RunInternalConfigUnset_InvalidProfileName(t *testing.T) { err := RunInternalConfigUnset("noColor") testutils.CheckExpectedError(t, err, &expectedErrorPattern) } + +// Test RunInternalConfigUnset function succeeds with case-insensitive key +func Test_RunInternalConfigUnset_CaseInsensitiveKeys(t *testing.T) { + testutils_koanf.InitKoanfs(t) + + err := RunInternalConfigUnset("NoCoLoR") + if err != nil { + t.Errorf("RunInternalConfigUnset returned error: %v", err) + } + + //Make sure the actual correct key was unset, not the case-insensitive one + vVal, err := profiles.GetOptionValue(options.RootColorOption) + if err != nil { + t.Errorf("GetOptionValue returned error: %v", err) + } + + if vVal != options.RootColorOption.DefaultValue.String() { + t.Errorf("Expected %s to be %s, got %v", options.RootColorOption.KoanfKey, options.RootColorOption.DefaultValue.String(), vVal) + } +} From 472e19e3d87d9f0d0315d0160888d6462d0d7569 Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Wed, 10 Sep 2025 11:17:29 -0600 Subject: [PATCH 2/2] gocritic lint fixes --- internal/commands/config/set_internal_test.go | 2 +- internal/commands/config/unset_internal_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/commands/config/set_internal_test.go b/internal/commands/config/set_internal_test.go index aee0517f..fb7de70a 100644 --- a/internal/commands/config/set_internal_test.go +++ b/internal/commands/config/set_internal_test.go @@ -131,7 +131,7 @@ func Test_RunInternalConfigSet_CaseInsensitiveKeys(t *testing.T) { t.Errorf("RunInternalConfigSet returned error: %v", err) } - //Make sure the actual correct key was set, not the case-insensitive one + // Make sure the actual correct key was set, not the case-insensitive one vVal, err := profiles.GetOptionValue(options.RootColorOption) if err != nil { t.Errorf("GetOptionValue returned error: %v", err) diff --git a/internal/commands/config/unset_internal_test.go b/internal/commands/config/unset_internal_test.go index 22d0d4c7..3f903cac 100644 --- a/internal/commands/config/unset_internal_test.go +++ b/internal/commands/config/unset_internal_test.go @@ -73,7 +73,7 @@ func Test_RunInternalConfigUnset_CaseInsensitiveKeys(t *testing.T) { t.Errorf("RunInternalConfigUnset returned error: %v", err) } - //Make sure the actual correct key was unset, not the case-insensitive one + // Make sure the actual correct key was unset, not the case-insensitive one vVal, err := profiles.GetOptionValue(options.RootColorOption) if err != nil { t.Errorf("GetOptionValue returned error: %v", err)