(t *testing.T)
| 226 | } |
| 227 | |
| 228 | func TestRunPullTermination(t *testing.T) { |
| 229 | ctx, cancel := context.WithCancel(context.Background()) |
| 230 | t.Cleanup(cancel) |
| 231 | |
| 232 | attachCh := make(chan struct{}) |
| 233 | fakeCLI := test.NewFakeCli(&fakeClient{ |
| 234 | createContainerFunc: func(options client.ContainerCreateOptions) (client.ContainerCreateResult, error) { |
| 235 | return client.ContainerCreateResult{}, errors.New("shouldn't try to create a container") |
| 236 | }, |
| 237 | containerAttachFunc: func(ctx context.Context, containerID string, options client.ContainerAttachOptions) (client.ContainerAttachResult, error) { |
| 238 | return client.ContainerAttachResult{}, errors.New("shouldn't try to attach to a container") |
| 239 | }, |
| 240 | imagePullFunc: func(ctx context.Context, parentReference string, options client.ImagePullOptions) (client.ImagePullResponse, error) { |
| 241 | server, respReader := net.Pipe() |
| 242 | t.Cleanup(func() { |
| 243 | _ = server.Close() |
| 244 | }) |
| 245 | go func() { |
| 246 | for range 100 { |
| 247 | select { |
| 248 | case <-ctx.Done(): |
| 249 | assert.NilError(t, server.Close(), "failed to close imageCreateFunc server") |
| 250 | return |
| 251 | default: |
| 252 | time.Sleep(100 * time.Millisecond) |
| 253 | } |
| 254 | } |
| 255 | }() |
| 256 | attachCh <- struct{}{} |
| 257 | return fakeStreamResult{ReadCloser: respReader}, nil |
| 258 | }, |
| 259 | Version: client.MaxAPIVersion, |
| 260 | }) |
| 261 | |
| 262 | cmd := newRunCommand(fakeCLI) |
| 263 | cmd.SetOut(io.Discard) |
| 264 | cmd.SetErr(io.Discard) |
| 265 | cmd.SetArgs([]string{"--pull", "always", "foobar:latest"}) |
| 266 | |
| 267 | cmdErrC := make(chan error, 1) |
| 268 | go func() { |
| 269 | cmdErrC <- cmd.ExecuteContext(ctx) |
| 270 | }() |
| 271 | |
| 272 | select { |
| 273 | case <-time.After(5 * time.Second): |
| 274 | t.Fatal("imageCreateFunc was not called before the timeout") |
| 275 | case <-attachCh: |
| 276 | } |
| 277 | |
| 278 | cancel() |
| 279 | |
| 280 | select { |
| 281 | case cmdErr := <-cmdErrC: |
| 282 | assert.Equal(t, cmdErr, cli.StatusError{ |
| 283 | Cause: context.Canceled, |
| 284 | StatusCode: 125, |
| 285 | Status: "docker: context canceled\n\nRun 'docker run --help' for more information", |
nothing calls this directly
no test coverage detected
searching dependent graphs…