1
0
Fork 0
forked from forgejo/forgejo

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>
This commit is contained in:
wxiaoguang 2022-10-15 20:18:31 +08:00 committed by GitHub
parent d98c5db58f
commit 677af6ac57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 11 deletions

View file

@ -27,15 +27,13 @@ func TestRunWithContextStd(t *testing.T) {
assert.Empty(t, stdout)
}
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)
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)
subCmd := "version"
cmd = NewCommand(context.Background()).AddDynamicArguments(subCmd) // for test purpose only, the sub-command should never be dynamic for production