Skip to content

Commit

Permalink
#53 Update the tests to include check for the short follow arg name
Browse files Browse the repository at this point in the history
  • Loading branch information
zshamrock committed Apr 29, 2018
1 parent 3c638b2 commit b8d3196
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,37 @@ import (
)

func TestGetCommand(t *testing.T) {
flags := flag.FlagSet{}
flags.Bool("follow", false, "")
commandText := "tail -f -n 10 logs/rest.log"
flags.Parse([]string{"--", "--follow", "dev", commandText})
app := cli.NewApp()
context := cli.NewContext(app, &flags, nil)
command, extraArgs := getCommand(context, true)
if !command.IsAdHoc() {
t.Errorf("Command name should be ad-hoc, but got %s", command.name)
}
if command.command != commandText {
t.Errorf("Command should be %s, but got %s", commandText, command.command)
}
if extraArgs != "" {
t.Errorf("Extra args should be empty, but got %s", extraArgs)
followFlags := []string{"-f", "--follow"}
for _, followFlag := range followFlags {
flags := flag.FlagSet{}
flags.Bool("follow", false, "")
commandText := "tail -f -n 10 logs/rest.log"
flags.Parse([]string{"--", followFlag, "dev", commandText})
app := cli.NewApp()
context := cli.NewContext(app, &flags, nil)
command, extraArgs := getCommand(context, true)
if !command.IsAdHoc() {
t.Errorf("Command name should be ad-hoc, but got %s", command.name)
}
if command.command != commandText {
t.Errorf("Command should be %s, but got %s", commandText, command.command)
}
if extraArgs != "" {
t.Errorf("Extra args should be empty, but got %s", extraArgs)
}
}
}

func TestContainsFollow(t *testing.T) {
flags := flag.FlagSet{}
flags.Bool("follow", false, "")
flags.Parse([]string{"--", "--follow", "dev", "tail -f -n 10 logs/rest.log"})
app := cli.NewApp()
context := cli.NewContext(app, &flags, nil)
follow := ContainsFollow(context)
if !follow {
t.Error("Should contain follow")
followFlags := []string{"-f", "--follow"}
for _, followFlag := range followFlags {
flags := flag.FlagSet{}
flags.Parse([]string{"--", followFlag, "dev", "tail -f -n 10 logs/rest.log"})
app := cli.NewApp()
context := cli.NewContext(app, &flags, nil)
follow := ContainsFollow(context)
if !follow {
t.Error("Should contain follow")
}
}
}

0 comments on commit b8d3196

Please sign in to comment.