docker_cli_top_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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) TestTopMultipleArgs(c *check.C) {
  8. testRequires(c, DaemonIsLinux)
  9. out, _ := dockerCmd(c, "run", "-i", "-d", "busybox", "top")
  10. cleanedContainerID := strings.TrimSpace(out)
  11. out, _ = dockerCmd(c, "top", cleanedContainerID, "-o", "pid")
  12. c.Assert(out, checker.Contains, "PID", check.Commentf("did not see PID after top -o pid: %s", out))
  13. }
  14. func (s *DockerSuite) TestTopNonPrivileged(c *check.C) {
  15. testRequires(c, DaemonIsLinux)
  16. out, _ := dockerCmd(c, "run", "-i", "-d", "busybox", "top")
  17. cleanedContainerID := strings.TrimSpace(out)
  18. out1, _ := dockerCmd(c, "top", cleanedContainerID)
  19. out2, _ := dockerCmd(c, "top", cleanedContainerID)
  20. dockerCmd(c, "kill", cleanedContainerID)
  21. c.Assert(out1, checker.Contains, "top", check.Commentf("top should've listed `top` in the process list, but failed the first time"))
  22. c.Assert(out2, checker.Contains, "top", check.Commentf("top should've listed `top` in the process list, but failed the second time"))
  23. }
  24. func (s *DockerSuite) TestTopPrivileged(c *check.C) {
  25. testRequires(c, DaemonIsLinux, NotUserNamespace)
  26. out, _ := dockerCmd(c, "run", "--privileged", "-i", "-d", "busybox", "top")
  27. cleanedContainerID := strings.TrimSpace(out)
  28. out1, _ := dockerCmd(c, "top", cleanedContainerID)
  29. out2, _ := dockerCmd(c, "top", cleanedContainerID)
  30. dockerCmd(c, "kill", cleanedContainerID)
  31. c.Assert(out1, checker.Contains, "top", check.Commentf("top should've listed `top` in the process list, but failed the first time"))
  32. c.Assert(out2, checker.Contains, "top", check.Commentf("top should've listed `top` in the process list, but failed the second time"))
  33. }