(t *testing.T)
| 167 | } |
| 168 | |
| 169 | func 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 | |
| 219 | func execCreateWithID(_ string, _ client.ExecCreateOptions) (client.ExecCreateResult, error) { |
| 220 | return client.ExecCreateResult{ID: "exec-id"}, nil |
nothing calls this directly
no test coverage detected
searching dependent graphs…