docker_api_resize_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package main
  2. import (
  3. "os/exec"
  4. "strings"
  5. "testing"
  6. )
  7. func TestResizeApiResponse(t *testing.T) {
  8. runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
  9. out, _, err := runCommandWithOutput(runCmd)
  10. if err != nil {
  11. t.Fatalf(out, err)
  12. }
  13. defer deleteAllContainers()
  14. cleanedContainerID := stripTrailingCharacters(out)
  15. endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
  16. _, err = sockRequest("POST", endpoint, nil)
  17. if err != nil {
  18. t.Fatalf("resize Request failed %v", err)
  19. }
  20. logDone("container resize - when started")
  21. }
  22. func TestResizeApiResponseWhenContainerNotStarted(t *testing.T) {
  23. runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
  24. out, _, err := runCommandWithOutput(runCmd)
  25. if err != nil {
  26. t.Fatalf(out, err)
  27. }
  28. defer deleteAllContainers()
  29. cleanedContainerID := stripTrailingCharacters(out)
  30. // make sure the exited cintainer is not running
  31. runCmd = exec.Command(dockerBinary, "wait", cleanedContainerID)
  32. out, _, err = runCommandWithOutput(runCmd)
  33. if err != nil {
  34. t.Fatalf(out, err)
  35. }
  36. endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
  37. body, err := sockRequest("POST", endpoint, nil)
  38. if err == nil {
  39. t.Fatalf("resize should fail when container is not started")
  40. }
  41. if !strings.Contains(string(body), "Cannot resize container") && !strings.Contains(string(body), cleanedContainerID) {
  42. t.Fatalf("resize should fail with message 'Cannot resize container' but instead received %s", string(body))
  43. }
  44. logDone("container resize - when not started should not resize")
  45. }