docker_cli_pause_test.go 2.1 KB

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