github.com/vincentwoo/docker@v0.7.3-0.20160116130405-82401a4b13c0/integration-cli/docker_cli_pause_test.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/docker/docker/pkg/integration/checker" 8 "github.com/go-check/check" 9 ) 10 11 func (s *DockerSuite) TestPause(c *check.C) { 12 testRequires(c, DaemonIsLinux) 13 defer unpauseAllContainers() 14 15 name := "testeventpause" 16 dockerCmd(c, "run", "-d", "--name", name, "busybox", "top") 17 18 dockerCmd(c, "pause", name) 19 pausedContainers, err := getSliceOfPausedContainers() 20 c.Assert(err, checker.IsNil) 21 c.Assert(len(pausedContainers), checker.Equals, 1) 22 23 dockerCmd(c, "unpause", name) 24 25 out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix())) 26 events := strings.Split(strings.TrimSpace(out), "\n") 27 actions := eventActionsByIDAndType(c, events, name, "container") 28 29 c.Assert(actions[len(actions)-2], checker.Equals, "pause") 30 c.Assert(actions[len(actions)-1], checker.Equals, "unpause") 31 } 32 33 func (s *DockerSuite) TestPauseMultipleContainers(c *check.C) { 34 testRequires(c, DaemonIsLinux) 35 defer unpauseAllContainers() 36 37 containers := []string{ 38 "testpausewithmorecontainers1", 39 "testpausewithmorecontainers2", 40 } 41 for _, name := range containers { 42 dockerCmd(c, "run", "-d", "--name", name, "busybox", "top") 43 } 44 dockerCmd(c, append([]string{"pause"}, containers...)...) 45 pausedContainers, err := getSliceOfPausedContainers() 46 c.Assert(err, checker.IsNil) 47 c.Assert(len(pausedContainers), checker.Equals, len(containers)) 48 49 dockerCmd(c, append([]string{"unpause"}, containers...)...) 50 51 out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix())) 52 events := strings.Split(strings.TrimSpace(out), "\n") 53 54 for _, name := range containers { 55 actions := eventActionsByIDAndType(c, events, name, "container") 56 57 c.Assert(actions[len(actions)-2], checker.Equals, "pause") 58 c.Assert(actions[len(actions)-1], checker.Equals, "unpause") 59 } 60 } 61 62 func (s *DockerSuite) TestPauseFailsOnWindows(c *check.C) { 63 testRequires(c, DaemonIsWindows) 64 dockerCmd(c, "run", "-d", "--name=test", "busybox", "sleep 3") 65 out, _, _ := dockerCmdWithError("pause", "test") 66 c.Assert(out, checker.Contains, "Windows: Containers cannot be paused") 67 }