(t *testing.T, r io.ReadCloser, w io.Writer, args ...string)
| 58 | var discard = io.NopCloser(bytes.NewBuffer(nil)) |
| 59 | |
| 60 | func runCliCommand(t *testing.T, r io.ReadCloser, w io.Writer, args ...string) error { |
| 61 | t.Helper() |
| 62 | if r == nil { |
| 63 | r = discard |
| 64 | } |
| 65 | if w == nil { |
| 66 | w = io.Discard |
| 67 | } |
| 68 | ctx, cancel := context.WithCancel(context.TODO()) |
| 69 | defer cancel() |
| 70 | |
| 71 | cli, err := command.NewDockerCli( |
| 72 | command.WithBaseContext(ctx), |
| 73 | command.WithInputStream(r), |
| 74 | command.WithCombinedStreams(w)) |
| 75 | assert.NilError(t, err) |
| 76 | tcmd := newDockerCommand(cli) |
| 77 | |
| 78 | tcmd.SetArgs(args) |
| 79 | cmd, _, err := tcmd.HandleGlobalFlags() |
| 80 | assert.NilError(t, err) |
| 81 | assert.NilError(t, tcmd.Initialize()) |
| 82 | return cmd.Execute() |
| 83 | } |
| 84 | |
| 85 | func TestExitStatusForInvalidSubcommandWithHelpFlag(t *testing.T) { |
| 86 | err := runCliCommand(t, nil, nil, "help", "invalid") |
no test coverage detected
searching dependent graphs…