docker_cli_top_test.go 1.8 KB

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