docker_api_resize_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 := strings.TrimSpace(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 TestResizeApiHeightWidthNoInt(t *testing.T) {
  23. runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
  24. out, _, err := runCommandWithOutput(runCmd)
  25. if err != nil {
  26. t.Fatalf(out, err)
  27. }
  28. defer deleteAllContainers()
  29. cleanedContainerID := strings.TrimSpace(out)
  30. endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar"
  31. _, err = sockRequest("POST", endpoint, nil)
  32. if err == nil {
  33. t.Fatal("Expected resize Request to fail")
  34. }
  35. logDone("container resize - height, width no int fail")
  36. }
  37. func TestResizeApiResponseWhenContainerNotStarted(t *testing.T) {
  38. runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
  39. out, _, err := runCommandWithOutput(runCmd)
  40. if err != nil {
  41. t.Fatalf(out, err)
  42. }
  43. defer deleteAllContainers()
  44. cleanedContainerID := strings.TrimSpace(out)
  45. // make sure the exited container is not running
  46. runCmd = exec.Command(dockerBinary, "wait", cleanedContainerID)
  47. out, _, err = runCommandWithOutput(runCmd)
  48. if err != nil {
  49. t.Fatalf(out, err)
  50. }
  51. endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
  52. body, err := sockRequest("POST", endpoint, nil)
  53. if err == nil {
  54. t.Fatalf("resize should fail when container is not started")
  55. }
  56. if !strings.Contains(string(body), "Cannot resize container") && !strings.Contains(string(body), cleanedContainerID) {
  57. t.Fatalf("resize should fail with message 'Cannot resize container' but instead received %s", string(body))
  58. }
  59. logDone("container resize - when not started should not resize")
  60. }