diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2022-10-15 20:18:31 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-15 14:18:31 +0200 |
commit | 677af6ac57295a9e8795a8ab3f29e284f2247fb6 (patch) | |
tree | 049d790d6d9359189bf90908fab29cd14e5b0d76 /modules/git/command_test.go | |
parent | d98c5db58fdeded983bf5c0fe781fd7b77a1235f (diff) | |
download | gitea-677af6ac57295a9e8795a8ab3f29e284f2247fb6.tar.gz gitea-677af6ac57295a9e8795a8ab3f29e284f2247fb6.zip |
Follow improve code quality (#21465)
After some discussion, introduce a new slice `brokenArgs` to make
`gitCmd.Run()` return errors if any dynamic argument is invalid.
Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'modules/git/command_test.go')
-rw-r--r-- | modules/git/command_test.go | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/modules/git/command_test.go b/modules/git/command_test.go index c965ea230d..52d25c9c74 100644 --- a/modules/git/command_test.go +++ b/modules/git/command_test.go @@ -27,15 +27,13 @@ func TestRunWithContextStd(t *testing.T) { assert.Empty(t, stdout) } - assert.Panics(t, func() { - cmd = NewCommand(context.Background()) - cmd.AddDynamicArguments("-test") - }) - - assert.Panics(t, func() { - cmd = NewCommand(context.Background()) - cmd.AddDynamicArguments("--test") - }) + cmd = NewCommand(context.Background()) + cmd.AddDynamicArguments("-test") + assert.ErrorIs(t, cmd.Run(&RunOpts{}), ErrBrokenCommand) + + cmd = NewCommand(context.Background()) + cmd.AddDynamicArguments("--test") + assert.ErrorIs(t, cmd.Run(&RunOpts{}), ErrBrokenCommand) subCmd := "version" cmd = NewCommand(context.Background()).AddDynamicArguments(subCmd) // for test purpose only, the sub-command should never be dynamic for production |