diff --git a/cmd/skaffold/app/cmd/commands_test.go b/cmd/skaffold/app/cmd/commands_test.go index b40936d2691..e980e70d31e 100644 --- a/cmd/skaffold/app/cmd/commands_test.go +++ b/cmd/skaffold/app/cmd/commands_test.go @@ -24,6 +24,7 @@ import ( "testing" "github.com/GoogleContainerTools/skaffold/testutil" + "github.com/spf13/pflag" ) func TestNewCmdDescription(t *testing.T) { @@ -77,3 +78,34 @@ func TestNewCmdOutput(t *testing.T) { testutil.CheckErrorAndDeepEqual(t, false, err, "test output: [arg1]\n", buf.String()) } + +func TestNewCmdWithFlags(t *testing.T) { + cmd := NewCmd(nil, "").WithFlags(func(flagSet *pflag.FlagSet) { + flagSet.Bool("test", false, "usage") + }).NoArgs(nil) + + flags := listFlags(cmd.Flags()) + + testutil.CheckDeepEqual(t, 1, len(flags)) + testutil.CheckDeepEqual(t, "usage", flags["test"].Usage) +} + +func TestNewCmdWithCommonFlags(t *testing.T) { + cmd := NewCmd(nil, "run").WithCommonFlags().NoArgs(nil) + + flags := listFlags(cmd.Flags()) + + if _, present := flags["profile"]; !present { + t.Error("Expected flag `profile` to be added") + } +} + +func listFlags(set *pflag.FlagSet) map[string]*pflag.Flag { + flagsByName := make(map[string]*pflag.Flag) + + set.VisitAll(func(f *pflag.Flag) { + flagsByName[f.Name] = f + }) + + return flagsByName +}