docker_cli_top_test.go 895 B

1234567891011121314151617181920212223242526272829303132
  1. package main
  2. import (
  3. "fmt"
  4. "os/exec"
  5. "strings"
  6. "testing"
  7. )
  8. func TestTop(t *testing.T) {
  9. runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "sleep", "20")
  10. out, _, err := runCommandWithOutput(runCmd)
  11. errorOut(err, t, fmt.Sprintf("failed to start the container: %v", err))
  12. cleanedContainerID := stripTrailingCharacters(out)
  13. topCmd := exec.Command(dockerBinary, "top", cleanedContainerID)
  14. out, _, err = runCommandWithOutput(topCmd)
  15. errorOut(err, t, fmt.Sprintf("failed to run top: %v %v", out, err))
  16. killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID)
  17. _, err = runCommand(killCmd)
  18. errorOut(err, t, fmt.Sprintf("failed to kill container: %v", err))
  19. go deleteContainer(cleanedContainerID)
  20. if !strings.Contains(out, "sleep 20") {
  21. t.Fatal("top should've listed sleep 20 in the process list")
  22. }
  23. logDone("top - sleep process should be listed")
  24. }