github.com/noxiouz/docker@v0.7.3-0.20160629055221-3d231c78e8c5/integration-cli/docker_cli_kill_test.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "net/http" 6 "strings" 7 8 "github.com/docker/docker/pkg/integration/checker" 9 "github.com/go-check/check" 10 ) 11 12 func (s *DockerSuite) TestKillContainer(c *check.C) { 13 out, _ := runSleepingContainer(c, "-d") 14 cleanedContainerID := strings.TrimSpace(out) 15 c.Assert(waitRun(cleanedContainerID), check.IsNil) 16 17 dockerCmd(c, "kill", cleanedContainerID) 18 19 out, _ = dockerCmd(c, "ps", "-q") 20 c.Assert(out, checker.Not(checker.Contains), cleanedContainerID, check.Commentf("killed container is still running")) 21 22 } 23 24 func (s *DockerSuite) TestKillOffStoppedContainer(c *check.C) { 25 out, _ := runSleepingContainer(c, "-d") 26 cleanedContainerID := strings.TrimSpace(out) 27 28 dockerCmd(c, "stop", cleanedContainerID) 29 30 _, _, err := dockerCmdWithError("kill", "-s", "30", cleanedContainerID) 31 c.Assert(err, check.Not(check.IsNil), check.Commentf("Container %s is not running", cleanedContainerID)) 32 } 33 34 func (s *DockerSuite) TestKillDifferentUserContainer(c *check.C) { 35 // TODO Windows: Windows does not yet support -u (Feb 2016). 36 testRequires(c, DaemonIsLinux) 37 out, _ := dockerCmd(c, "run", "-u", "daemon", "-d", "busybox", "top") 38 cleanedContainerID := strings.TrimSpace(out) 39 c.Assert(waitRun(cleanedContainerID), check.IsNil) 40 41 dockerCmd(c, "kill", cleanedContainerID) 42 43 out, _ = dockerCmd(c, "ps", "-q") 44 c.Assert(out, checker.Not(checker.Contains), cleanedContainerID, check.Commentf("killed container is still running")) 45 46 } 47 48 // regression test about correct signal parsing see #13665 49 func (s *DockerSuite) TestKillWithSignal(c *check.C) { 50 // Cannot port to Windows - does not support signals in the same was a Linux does 51 testRequires(c, DaemonIsLinux) 52 out, _ := dockerCmd(c, "run", "-d", "busybox", "top") 53 cid := strings.TrimSpace(out) 54 c.Assert(waitRun(cid), check.IsNil) 55 56 dockerCmd(c, "kill", "-s", "SIGWINCH", cid) 57 58 running := inspectField(c, cid, "State.Running") 59 60 c.Assert(running, checker.Equals, "true", check.Commentf("Container should be in running state after SIGWINCH")) 61 } 62 63 func (s *DockerSuite) TestKillWithInvalidSignal(c *check.C) { 64 out, _ := runSleepingContainer(c, "-d") 65 cid := strings.TrimSpace(out) 66 c.Assert(waitRun(cid), check.IsNil) 67 68 out, _, err := dockerCmdWithError("kill", "-s", "0", cid) 69 c.Assert(err, check.NotNil) 70 c.Assert(out, checker.Contains, "Invalid signal: 0", check.Commentf("Kill with an invalid signal didn't error out correctly")) 71 72 running := inspectField(c, cid, "State.Running") 73 c.Assert(running, checker.Equals, "true", check.Commentf("Container should be in running state after an invalid signal")) 74 75 out, _ = runSleepingContainer(c, "-d") 76 cid = strings.TrimSpace(out) 77 c.Assert(waitRun(cid), check.IsNil) 78 79 out, _, err = dockerCmdWithError("kill", "-s", "SIG42", cid) 80 c.Assert(err, check.NotNil) 81 c.Assert(out, checker.Contains, "Invalid signal: SIG42", check.Commentf("Kill with an invalid signal error out correctly")) 82 83 running = inspectField(c, cid, "State.Running") 84 c.Assert(running, checker.Equals, "true", check.Commentf("Container should be in running state after an invalid signal")) 85 86 } 87 88 func (s *DockerSuite) TestKillStoppedContainerAPIPre120(c *check.C) { 89 runSleepingContainer(c, "--name", "docker-kill-test-api", "-d") 90 dockerCmd(c, "stop", "docker-kill-test-api") 91 92 status, _, err := sockRequest("POST", fmt.Sprintf("/v1.19/containers/%s/kill", "docker-kill-test-api"), nil) 93 c.Assert(err, check.IsNil) 94 c.Assert(status, check.Equals, http.StatusNoContent) 95 }