diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-11-26 15:38:07 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-11-26 15:38:07 +0300 |
commit | 5c47f40128cd1dae68d270317d076f16fa801819 (patch) | |
tree | c86cf1d5bc7f923f1aa8283203a7b4578ee7985b | |
parent | e4eda3ecb4477ae94cba35ef296217a0d765b423 (diff) |
git: Convert tests to use proper git commands
Our safecmd tests currently have a set of tests which verify command
line parsing by creating non-existing commands like `git meow`. While
cute, the plan is to make our command verification stricter by
disallowing any commands which are not in our map of subcommands. "woof"
and "meow" unfortunately aren't going to be part of that map.
Let's replace them with git-update-ref(1) commands to prepare for that
change.
-rw-r--r-- | internal/git/safecmd_test.go | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/internal/git/safecmd_test.go b/internal/git/safecmd_test.go index f464e1f24..578d19585 100644 --- a/internal/git/safecmd_test.go +++ b/internal/git/safecmd_test.go @@ -88,21 +88,21 @@ func TestSafeCmdInvalidArg(t *testing.T) { }, { subCmd: git.SubCmd{ - Name: "meow", + Name: "update-ref", Flags: []git.Option{git.Flag{Name: "woof"}}, }, errMsg: `flag "woof" failed regex validation: invalid argument`, }, { subCmd: git.SubCmd{ - Name: "meow", + Name: "update-ref", Args: []string{"--tweet"}, }, errMsg: `positional arg "--tweet" cannot start with dash '-': invalid argument`, }, { subCmd: git.SubCmd{ - Name: "meow", + Name: "update-ref", Flags: []git.Option{git.SubSubCmd{"-invalid"}}, }, errMsg: `invalid sub-sub command name "-invalid": invalid argument`, @@ -142,25 +142,25 @@ func TestSafeCmdValid(t *testing.T) { }{ { desc: "no args", - subCmd: git.SubCmd{Name: "meow"}, - expectArgs: []string{"-c", hooksPath, "meow", endOfOptions}, + subCmd: git.SubCmd{Name: "update-ref"}, + expectArgs: []string{"-c", hooksPath, "update-ref", endOfOptions}, }, { desc: "single option", globals: []git.Option{ git.Flag{Name: "--aaaa-bbbb"}, }, - subCmd: git.SubCmd{Name: "cccc"}, - expectArgs: []string{"--aaaa-bbbb", "-c", hooksPath, "cccc", endOfOptions}, + subCmd: git.SubCmd{Name: "update-ref"}, + expectArgs: []string{"--aaaa-bbbb", "-c", hooksPath, "update-ref", endOfOptions}, }, { desc: "empty arg and postsep args", subCmd: git.SubCmd{ - Name: "meow", + Name: "update-ref", Args: []string{""}, PostSepArgs: []string{"-woof", ""}, }, - expectArgs: []string{"-c", hooksPath, "meow", "", endOfOptions, "--", "-woof", ""}, + expectArgs: []string{"-c", hooksPath, "update-ref", "", endOfOptions, "--", "-woof", ""}, }, { desc: "full blown", @@ -169,7 +169,7 @@ func TestSafeCmdValid(t *testing.T) { git.ValueFlag{"-b", "c"}, }, subCmd: git.SubCmd{ - Name: "d", + Name: "update-ref", Flags: []git.Option{ git.Flag{Name: "-e"}, git.ValueFlag{"-f", "g"}, @@ -178,19 +178,19 @@ func TestSafeCmdValid(t *testing.T) { Args: []string{"1", "2"}, PostSepArgs: []string{"3", "4", "5"}, }, - expectArgs: []string{"-a", "-b", "c", "-c", hooksPath, "d", "-e", "-f", "g", "-h=i", "1", "2", endOfOptions, "--", "3", "4", "5"}, + expectArgs: []string{"-a", "-b", "c", "-c", hooksPath, "update-ref", "-e", "-f", "g", "-h=i", "1", "2", endOfOptions, "--", "3", "4", "5"}, }, { desc: "output to stdout", subCmd: git.SubCmd{ - Name: "noun", + Name: "update-ref", Flags: []git.Option{ git.SubSubCmd{"verb"}, git.OutputToStdout, git.Flag{Name: "--adjective"}, }, }, - expectArgs: []string{"-c", hooksPath, "noun", "verb", "-", "--adjective", endOfOptions}, + expectArgs: []string{"-c", hooksPath, "update-ref", "verb", "-", "--adjective", endOfOptions}, }, { desc: "multiple value flags", @@ -199,14 +199,14 @@ func TestSafeCmdValid(t *testing.T) { git.ValueFlag{"--author", "a-gopher"}, }, subCmd: git.SubCmd{ - Name: "accept", + Name: "update-ref", Args: []string{"mr"}, Flags: []git.Option{ git.Flag{Name: "--is-important"}, git.ValueFlag{"--why", "looking-for-first-contribution"}, }, }, - expectArgs: []string{"--contributing", "--author", "a-gopher", "-c", hooksPath, "accept", "--is-important", "--why", "looking-for-first-contribution", "mr", endOfOptions}, + expectArgs: []string{"--contributing", "--author", "a-gopher", "-c", hooksPath, "update-ref", "--is-important", "--why", "looking-for-first-contribution", "mr", endOfOptions}, }, } { t.Run(tt.desc, func(t *testing.T) { @@ -256,9 +256,9 @@ func TestSafeCmdWithEnv(t *testing.T) { git.Flag{Name: "--aaaa-bbbb"}, } - subCmd := git.SubCmd{Name: "cccc"} + subCmd := git.SubCmd{Name: "update-ref"} endOfOptions := "--end-of-options" - expectArgs := []string{"--aaaa-bbbb", "-c", "core.hooksPath=" + hooks.Path(config.Config), "cccc", endOfOptions} + expectArgs := []string{"--aaaa-bbbb", "-c", "core.hooksPath=" + hooks.Path(config.Config), "update-ref", endOfOptions} env := []string{"TEST_VAR1=1", "TEST_VAR2=2"} |