github.com/torfuzx/docker@v1.8.1/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/go-check/check" 9 ) 10 11 func (s *DockerSuite) TestKillContainer(c *check.C) { 12 out, _ := dockerCmd(c, "run", "-d", "busybox", "top") 13 cleanedContainerID := strings.TrimSpace(out) 14 c.Assert(waitRun(cleanedContainerID), check.IsNil) 15 16 dockerCmd(c, "kill", cleanedContainerID) 17 18 out, _ = dockerCmd(c, "ps", "-q") 19 if strings.Contains(out, cleanedContainerID) { 20 c.Fatal("killed container is still running") 21 } 22 } 23 24 func (s *DockerSuite) TestKillofStoppedContainer(c *check.C) { 25 out, _ := dockerCmd(c, "run", "-d", "busybox", "top") 26 cleanedContainerID := strings.TrimSpace(out) 27 28 dockerCmd(c, "stop", cleanedContainerID) 29 30 _, _, err := dockerCmdWithError(c, "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 out, _ := dockerCmd(c, "run", "-u", "daemon", "-d", "busybox", "top") 36 cleanedContainerID := strings.TrimSpace(out) 37 c.Assert(waitRun(cleanedContainerID), check.IsNil) 38 39 dockerCmd(c, "kill", cleanedContainerID) 40 41 out, _ = dockerCmd(c, "ps", "-q") 42 if strings.Contains(out, cleanedContainerID) { 43 c.Fatal("killed container is still running") 44 } 45 } 46 47 // regression test about correct signal parsing see #13665 48 func (s *DockerSuite) TestKillWithSignal(c *check.C) { 49 out, _ := dockerCmd(c, "run", "-d", "busybox", "top") 50 cid := strings.TrimSpace(out) 51 c.Assert(waitRun(cid), check.IsNil) 52 53 dockerCmd(c, "kill", "-s", "SIGWINCH", cid) 54 55 running, _ := inspectField(cid, "State.Running") 56 if running != "true" { 57 c.Fatal("Container should be in running state after SIGWINCH") 58 } 59 } 60 61 func (s *DockerSuite) TestKillWithInvalidSignal(c *check.C) { 62 out, _ := dockerCmd(c, "run", "-d", "busybox", "top") 63 cid := strings.TrimSpace(out) 64 c.Assert(waitRun(cid), check.IsNil) 65 66 out, _, err := dockerCmdWithError(c, "kill", "-s", "0", cid) 67 c.Assert(err, check.NotNil) 68 if !strings.ContainsAny(out, "Invalid signal: 0") { 69 c.Fatal("Kill with an invalid signal didn't error out correctly") 70 } 71 72 running, _ := inspectField(cid, "State.Running") 73 if running != "true" { 74 c.Fatal("Container should be in running state after an invalid signal") 75 } 76 77 out, _ = dockerCmd(c, "run", "-d", "busybox", "top") 78 cid = strings.TrimSpace(out) 79 c.Assert(waitRun(cid), check.IsNil) 80 81 out, _, err = dockerCmdWithError(c, "kill", "-s", "SIG42", cid) 82 c.Assert(err, check.NotNil) 83 if !strings.ContainsAny(out, "Invalid signal: SIG42") { 84 c.Fatal("Kill with an invalid signal error out correctly") 85 } 86 87 running, _ = inspectField(cid, "State.Running") 88 if running != "true" { 89 c.Fatal("Container should be in running state after an invalid signal") 90 } 91 } 92 93 func (s *DockerSuite) TestKillofStoppedContainerAPIPre120(c *check.C) { 94 dockerCmd(c, "run", "--name", "docker-kill-test-api", "-d", "busybox", "top") 95 dockerCmd(c, "stop", "docker-kill-test-api") 96 97 status, _, err := sockRequest("POST", fmt.Sprintf("/v1.19/containers/%s/kill", "docker-kill-test-api"), nil) 98 c.Assert(err, check.IsNil) 99 c.Assert(status, check.Equals, http.StatusNoContent) 100 }