From 84726184108d88fdf5df64fa60d6b96a7f128ccf Mon Sep 17 00:00:00 2001 From: Artem Mikhalitsin Date: Mon, 3 Mar 2025 13:46:58 -0500 Subject: [PATCH] add more boolean test cases Signed-off-by: Artem Mikhalitsin --- pkg/cmd/load_plugins.go | 6 +++--- pkg/cmd/plugin_test.go | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/load_plugins.go b/pkg/cmd/load_plugins.go index 40de2d901..62b6518ef 100644 --- a/pkg/cmd/load_plugins.go +++ b/pkg/cmd/load_plugins.go @@ -152,8 +152,8 @@ func callPluginExecutable(pluginName string, main string, argv []string, out io. // Returns two sets of args: known and unknown (in that order) // Known args are flags that are consumed by the root `helm` command // Unknown args are any args that will not be consumed by helm, and that may be -// processed by the plugin plus -// The single exception is -h or --help, which is passed to the plugin +// processed by the plugin +// The single exception is -h or --help, which is passed to the plugin regardless func manuallyProcessArgs(args []string) ([]string, []string) { known := []string{} unknown := []string{} @@ -176,7 +176,7 @@ func manuallyProcessArgs(args []string) ([]string, []string) { "--registry-config", "--repository-cache", "--repository-config"} - kvargs = append(kvargs, boolArgs...) // bool args can also by kv i.e. `--debug=true` + kvargs = append(kvargs, boolArgs...) // boolean args can also be kv i.e. `--debug=true` // detects args with 'arg=val' syntax isKnownKvWithEquals := func(a string) bool { diff --git a/pkg/cmd/plugin_test.go b/pkg/cmd/plugin_test.go index 309491258..2ad07ac5e 100644 --- a/pkg/cmd/plugin_test.go +++ b/pkg/cmd/plugin_test.go @@ -35,11 +35,15 @@ func TestManuallyProcessArgs(t *testing.T) { "--debug", "--debug=true", "--debug", "true", + "--debug", "1", "--debug", "false", + "--debug", "0", "--kube-insecure-skip-tls-verify", "--kube-insecure-skip-tls-verify=true", "--kube-insecure-skip-tls-verify", "true", + "--kube-insecure-skip-tls-verify", "1", "--kube-insecure-skip-tls-verify", "false", + "--kube-insecure-skip-tls-verify", "0", "--foo", "bar", "--burst-limit", "123", "--burst-limit=123", @@ -58,18 +62,22 @@ func TestManuallyProcessArgs(t *testing.T) { "--qps=22", "--home=/tmp", "command", - "--debug", // check a boolean flag at the end to test possible out of bounds exception + "--debug", // test for possible out of bounds error when parsing boolean flags } expectKnown := []string{ "--debug", "--debug=true", "--debug", "true", + "--debug", "1", "--debug", "false", + "--debug", "0", "--kube-insecure-skip-tls-verify", "--kube-insecure-skip-tls-verify=true", "--kube-insecure-skip-tls-verify", "true", + "--kube-insecure-skip-tls-verify", "1", "--kube-insecure-skip-tls-verify", "false", + "--kube-insecure-skip-tls-verify", "0", "--burst-limit", "123", "--burst-limit=123", "--kubeconfig=/home/foo",