From ff392685bf1dc1a2c3fd25334fd48d5f653eee37 Mon Sep 17 00:00:00 2001 From: William Tam Date: Sun, 23 Feb 2020 19:12:17 -0500 Subject: [PATCH] pass slice of key/value pairs instead of strings (#13) --- pkg/odo/cli/pipelines/bootstrap_test.go | 32 +++++++++++++++++-------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/pkg/odo/cli/pipelines/bootstrap_test.go b/pkg/odo/cli/pipelines/bootstrap_test.go index 375a2ef55ff..221fe40ad39 100644 --- a/pkg/odo/cli/pipelines/bootstrap_test.go +++ b/pkg/odo/cli/pipelines/bootstrap_test.go @@ -8,6 +8,11 @@ import ( "github.com/spf13/cobra" ) +type keyValuePair struct { + key string + value string +} + func TestCompleteBootstrapOptions(t *testing.T) { completeTests := []struct { name string @@ -61,28 +66,28 @@ func TestValidateBootstrapOptions(t *testing.T) { } func TestBootstrapCommandWithMissingParams(t *testing.T) { cmdTests := []struct { - args []string + flags []keyValuePair wantErr string }{ - {[]string{"quay-username", "example", "github-token", "abc123", "dockerconfigjson", "~/"}, `Required flag(s) "git-repository" have/has not been set`}, - {[]string{"quay-username", "example", "github-token", "abc123", "git-repository", "example/repo"}, `Required flag(s) "dockerconfigjson" have/has not been set`}, - {[]string{"quay-username", "example", "dockerconfigjson", "~/", "git-repository", "example/repo"}, `Required flag(s) "github-token" have/has not been set`}, - {[]string{"github-token", "abc123", "dockerconfigjson", "~/", "git-repository", "example/repo"}, `Required flag(s) "quay-username" have/has not been set`}, + {[]keyValuePair{flag("quay-username", "example"), flag("github-token", "abc123"), flag("dockerconfigjson", "~/")}, `Required flag(s) "git-repository" have/has not been set`}, + {[]keyValuePair{flag("quay-username", "example"), flag("github-token", "abc123"), flag("git-repository", "example/repo")}, `Required flag(s) "dockerconfigjson" have/has not been set`}, + {[]keyValuePair{flag("quay-username", "example"), flag("dockerconfigjson", "~/"), flag("git-repository", "example/repo")}, `Required flag(s) "github-token" have/has not been set`}, + {[]keyValuePair{flag("github-token", "abc123"), flag("dockerconfigjson", "~/"), flag("git-repository", "example/repo")}, `Required flag(s) "quay-username" have/has not been set`}, } for _, tt := range cmdTests { - _, _, err := executeCommand(NewCmdBootstrap("bootstrap", "odo pipelines bootstrap"), tt.args...) + _, _, err := executeCommand(NewCmdBootstrap("bootstrap", "odo pipelines bootstrap"), tt.flags...) if err.Error() != tt.wantErr { t.Errorf("got %s, want %s", err, tt.wantErr) } } } -func executeCommand(cmd *cobra.Command, args ...string) (c *cobra.Command, output string, err error) { +func executeCommand(cmd *cobra.Command, flags ...keyValuePair) (c *cobra.Command, output string, err error) { buf := new(bytes.Buffer) cmd.SetOutput(buf) - cmd.Flags().Set(args[0], args[1]) - cmd.Flags().Set(args[2], args[3]) - cmd.Flags().Set(args[4], args[5]) + for _, flag := range flags { + cmd.Flags().Set(flag.key, flag.value) + } c, err = cmd.ExecuteC() return c, buf.String(), err } @@ -101,3 +106,10 @@ func matchError(t *testing.T, s string, e error) bool { } return match } + +func flag(k, v string) keyValuePair { + return keyValuePair{ + key: k, + value: v, + } +}