TestRunSimpleContainerExtended tests the timeout and detach behavior of RunSimpleContainerExtended.
(t *testing.T)
| 456 | |
| 457 | // TestRunSimpleContainerExtended tests the timeout and detach behavior of RunSimpleContainerExtended. |
| 458 | func TestRunSimpleContainerExtended(t *testing.T) { |
| 459 | basename := util.RandString(6) |
| 460 | |
| 461 | // timeout=0 means detach: should return immediately without waiting for the container to finish. |
| 462 | err := dockerutil.Pull("busybox:latest") |
| 463 | require.NoError(t, err) |
| 464 | containerName := "TestRunSimpleContainerExtended-detach-" + basename |
| 465 | start := time.Now() |
| 466 | cID, _, err := dockerutil.RunSimpleContainerExtended(containerName, &container.Config{ |
| 467 | Image: "busybox:latest", |
| 468 | Cmd: []string{"sleep", "30"}, |
| 469 | }, &container.HostConfig{}, false, 0) |
| 470 | require.NoError(t, err) |
| 471 | require.NotEmpty(t, cID) |
| 472 | t.Cleanup(func() { _ = dockerutil.RemoveContainer(cID) }) |
| 473 | require.Less(t, time.Since(start), 10*time.Second, "detach should return immediately, not wait for container") |
| 474 | // Container should still be running since we didn't wait. |
| 475 | info, err := dockerutil.InspectContainer(containerName) |
| 476 | require.NoError(t, err) |
| 477 | require.True(t, info.State.Running) |
| 478 | |
| 479 | // A short timeout should expire and return a timeout error for a container that sleeps longer. |
| 480 | _, _, err = dockerutil.RunSimpleContainerExtended("TestRunSimpleContainerExtended-timeout-"+basename, &container.Config{ |
| 481 | Image: "busybox:latest", |
| 482 | Cmd: []string{"sleep", "30"}, |
| 483 | }, &container.HostConfig{}, true, 1*time.Second) |
| 484 | require.Error(t, err) |
| 485 | require.Contains(t, err.Error(), "timed out after") |
| 486 | } |
| 487 | |
| 488 | // TestGetBoundHostPorts() checks to see that the ports expected |
| 489 | // to be exposed on a container actually are exposed. |
nothing calls this directly
no test coverage detected