MCPcopy Create free account
hub / github.com/docker/cli / TestKillContainer

Function TestKillContainer

e2e/container/kill_test.go:13–31  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestKillContainer(t *testing.T) {
14 result := icmd.RunCommand("docker", "run", "-d", fixtures.AlpineImage, "top")
15 result.Assert(t, icmd.Success)
16
17 containerID := strings.TrimSpace(result.Stdout())
18
19 // Kill with SIGTERM should kill the process
20 result = icmd.RunCmd(icmd.Command("docker", "kill", "-s", "SIGTERM", containerID))
21
22 result.Assert(t, icmd.Success)
23 poll.WaitOn(t, containerStatus(t, containerID, "exited"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second))
24
25 // Kill on a stop container should return an error
26 result = icmd.RunCmd(icmd.Command("docker", "kill", containerID))
27 result.Assert(t, icmd.Expected{
28 ExitCode: 1,
29 Err: "is not running",
30 })
31}
32
33func containerStatus(t *testing.T, containerID, status string) func(poll.LogT) poll.Result {
34 t.Helper()

Callers

nothing calls this directly

Calls 2

containerStatusFunction · 0.85
CommandMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…