From 1e981bdc5296a77c6c11b68d7c7ea8530b7954bc 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 c1ea46b5e..162454e6b 100644 --- a/pkg/cmd/load_plugins.go +++ b/pkg/cmd/load_plugins.go @@ -161,8 +161,8 @@ func processParent(cmd *cobra.Command, args []string) ([]string, error) { // 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{} @@ -185,7 +185,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 4c066ff47..634fdefd4 100644 --- a/pkg/cmd/plugin_test.go +++ b/pkg/cmd/plugin_test.go @@ -36,11 +36,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", @@ -59,18 +63,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",