docker_cli_top_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package main
  2. import (
  3. "strings"
  4. "github.com/go-check/check"
  5. )
  6. func (s *DockerSuite) TestTopMultipleArgs(c *check.C) {
  7. testRequires(c, DaemonIsLinux)
  8. out, _ := dockerCmd(c, "run", "-i", "-d", "busybox", "top")
  9. cleanedContainerID := strings.TrimSpace(out)
  10. out, _ = dockerCmd(c, "top", cleanedContainerID, "-o", "pid")
  11. if !strings.Contains(out, "PID") {
  12. c.Fatalf("did not see PID after top -o pid: %s", out)
  13. }
  14. }
  15. func (s *DockerSuite) TestTopNonPrivileged(c *check.C) {
  16. testRequires(c, DaemonIsLinux)
  17. out, _ := dockerCmd(c, "run", "-i", "-d", "busybox", "top")
  18. cleanedContainerID := strings.TrimSpace(out)
  19. out1, _ := dockerCmd(c, "top", cleanedContainerID)
  20. out2, _ := dockerCmd(c, "top", cleanedContainerID)
  21. out, _ = dockerCmd(c, "kill", cleanedContainerID)
  22. if !strings.Contains(out1, "top") && !strings.Contains(out2, "top") {
  23. c.Fatal("top should've listed `top` in the process list, but failed twice")
  24. } else if !strings.Contains(out1, "top") {
  25. c.Fatal("top should've listed `top` in the process list, but failed the first time")
  26. } else if !strings.Contains(out2, "top") {
  27. c.Fatal("top should've listed `top` in the process list, but failed the second itime")
  28. }
  29. }
  30. func (s *DockerSuite) TestTopPrivileged(c *check.C) {
  31. testRequires(c, DaemonIsLinux)
  32. out, _ := dockerCmd(c, "run", "--privileged", "-i", "-d", "busybox", "top")
  33. cleanedContainerID := strings.TrimSpace(out)
  34. out1, _ := dockerCmd(c, "top", cleanedContainerID)
  35. out2, _ := dockerCmd(c, "top", cleanedContainerID)
  36. out, _ = dockerCmd(c, "kill", cleanedContainerID)
  37. if !strings.Contains(out1, "top") && !strings.Contains(out2, "top") {
  38. c.Fatal("top should've listed `top` in the process list, but failed twice")
  39. } else if !strings.Contains(out1, "top") {
  40. c.Fatal("top should've listed `top` in the process list, but failed the first time")
  41. } else if !strings.Contains(out2, "top") {
  42. c.Fatal("top should've listed `top` in the process list, but failed the second itime")
  43. }
  44. }