MCPcopy Index your code
hub / github.com/docker/cli / runCliCommand

Function runCliCommand

cmd/docker/docker_test.go:60–83  ·  view source on GitHub ↗
(t *testing.T, r io.ReadCloser, w io.Writer, args ...string)

Source from the content-addressed store, hash-verified

58var discard = io.NopCloser(bytes.NewBuffer(nil))
59
60func 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
85func TestExitStatusForInvalidSubcommandWithHelpFlag(t *testing.T) {
86 err := runCliCommand(t, nil, nil, "help", "invalid")

Calls 4

newDockerCommandFunction · 0.85
SetArgsMethod · 0.80
HandleGlobalFlagsMethod · 0.80
InitializeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…