(t *testing.T)
| 365 | } |
| 366 | |
| 367 | func TestContainerWait(t *testing.T) { |
| 368 | t.Parallel() |
| 369 | |
| 370 | client, err := newClient(t, address) |
| 371 | if err != nil { |
| 372 | t.Fatal(err) |
| 373 | } |
| 374 | defer client.Close() |
| 375 | |
| 376 | var ( |
| 377 | image Image |
| 378 | ctx, cancel = testContext(t) |
| 379 | id = t.Name() |
| 380 | ) |
| 381 | defer cancel() |
| 382 | |
| 383 | image, err = client.GetImage(ctx, testImage) |
| 384 | if err != nil { |
| 385 | t.Fatal(err) |
| 386 | } |
| 387 | |
| 388 | container, err := client.NewContainer(ctx, id, WithNewSnapshot(id, image), WithNewSpec(oci.WithImageConfig(image), longCommand)) |
| 389 | if err != nil { |
| 390 | t.Fatal(err) |
| 391 | } |
| 392 | defer container.Delete(ctx) |
| 393 | |
| 394 | task, err := container.NewTask(ctx, empty()) |
| 395 | if err != nil { |
| 396 | t.Fatal(err) |
| 397 | } |
| 398 | defer task.Delete(ctx) |
| 399 | |
| 400 | ctx2, cancle2 := context.WithCancel(ctx) |
| 401 | cancle2() |
| 402 | statusErrC, _ := task.Wait(ctx2) |
| 403 | s := <-statusErrC |
| 404 | require.Error(t, s.Error(), "expected wait error, but got nil") |
| 405 | |
| 406 | statusC, err := task.Wait(ctx) |
| 407 | if err != nil { |
| 408 | t.Fatal(err) |
| 409 | } |
| 410 | |
| 411 | if err := task.Start(ctx); err != nil { |
| 412 | t.Fatal(err) |
| 413 | } |
| 414 | if err := task.Kill(ctx, syscall.SIGKILL); err != nil { |
| 415 | t.Fatal(err) |
| 416 | } |
| 417 | <-statusC |
| 418 | |
| 419 | err = task.Kill(ctx, syscall.SIGTERM) |
| 420 | if err == nil { |
| 421 | t.Fatal("second call to kill should return an error") |
| 422 | } |
| 423 | if !errdefs.IsNotFound(err) { |
| 424 | t.Errorf("expected error %q but received %q", errdefs.ErrNotFound, err) |
nothing calls this directly
no test coverage detected
searching dependent graphs…