From b8d3196083cd743600ca51db7dca7b7a1889046d Mon Sep 17 00:00:00 2001 From: Aliaksandr Kazlou Date: Mon, 30 Apr 2018 00:54:13 +0300 Subject: [PATCH] #53 Update the tests to include check for the short follow arg name --- command/command_test.go | 51 ++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/command/command_test.go b/command/command_test.go index ebd43f3..9fb25a9 100644 --- a/command/command_test.go +++ b/command/command_test.go @@ -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") + } } }