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

Function TestRunExec

cli/command/container/exec_test.go:169–217  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

167}
168
169func TestRunExec(t *testing.T) {
170 testcases := []struct {
171 doc string
172 options ExecOptions
173 client *fakeClient
174 expectedError string
175 expectedOut string
176 expectedErr string
177 }{
178 {
179 doc: "successful detach",
180 options: withDefaultOpts(ExecOptions{
181 Detach: true,
182 }),
183 client: &fakeClient{execCreateFunc: execCreateWithID},
184 },
185 {
186 doc: "inspect error",
187 options: NewExecOptions(),
188 client: &fakeClient{
189 inspectFunc: func(string) (client.ContainerInspectResult, error) {
190 return client.ContainerInspectResult{}, errors.New("failed inspect")
191 },
192 },
193 expectedError: "failed inspect",
194 },
195 {
196 doc: "missing exec ID",
197 options: NewExecOptions(),
198 expectedError: "exec ID empty",
199 client: &fakeClient{},
200 },
201 }
202
203 for _, testcase := range testcases {
204 t.Run(testcase.doc, func(t *testing.T) {
205 fakeCLI := test.NewFakeCli(testcase.client)
206
207 err := RunExec(context.TODO(), fakeCLI, "the-container", testcase.options)
208 if testcase.expectedError != "" {
209 assert.ErrorContains(t, err, testcase.expectedError)
210 } else if !assert.Check(t, err) {
211 return
212 }
213 assert.Check(t, is.Equal(testcase.expectedOut, fakeCLI.OutBuffer().String()))
214 assert.Check(t, is.Equal(testcase.expectedErr, fakeCLI.ErrBuffer().String()))
215 })
216 }
217}
218
219func execCreateWithID(_ string, _ client.ExecCreateOptions) (client.ExecCreateResult, error) {
220 return client.ExecCreateResult{ID: "exec-id"}, nil

Callers

nothing calls this directly

Calls 6

OutBufferMethod · 0.95
ErrBufferMethod · 0.95
withDefaultOptsFunction · 0.85
NewExecOptionsFunction · 0.85
RunExecFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…