docker_cli_pause_test.go 2.0 KB

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