Skip to content

Commit

Permalink
Add missing tests for cmd Builder
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <[email protected]>
  • Loading branch information
dgageot committed May 27, 2019
1 parent 7ad40f7 commit c273b07
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions cmd/skaffold/app/cmd/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"testing"

"github.com/GoogleContainerTools/skaffold/testutil"
"github.com/spf13/pflag"
)

func TestNewCmdDescription(t *testing.T) {
Expand Down Expand Up @@ -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
}

0 comments on commit c273b07

Please sign in to comment.