docker_api_resize_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package main
  2. import (
  3. "net/http"
  4. "os/exec"
  5. "strings"
  6. "github.com/go-check/check"
  7. )
  8. func (s *DockerSuite) TestResizeApiResponse(c *check.C) {
  9. runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
  10. out, _, err := runCommandWithOutput(runCmd)
  11. if err != nil {
  12. c.Fatalf(out, err)
  13. }
  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. c.Fatalf("resize Request failed %v", err)
  19. }
  20. }
  21. func (s *DockerSuite) TestResizeApiHeightWidthNoInt(c *check.C) {
  22. runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
  23. out, _, err := runCommandWithOutput(runCmd)
  24. if err != nil {
  25. c.Fatalf(out, err)
  26. }
  27. cleanedContainerID := strings.TrimSpace(out)
  28. endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar"
  29. status, _, err := sockRequest("POST", endpoint, nil)
  30. if err == nil {
  31. c.Fatal("Expected resize Request to fail")
  32. }
  33. if status != http.StatusInternalServerError {
  34. c.Fatalf("Status expected %d, got %d", http.StatusInternalServerError, status)
  35. }
  36. }
  37. func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) {
  38. runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
  39. out, _, err := runCommandWithOutput(runCmd)
  40. if err != nil {
  41. c.Fatalf(out, err)
  42. }
  43. cleanedContainerID := strings.TrimSpace(out)
  44. // make sure the exited container is not running
  45. runCmd = exec.Command(dockerBinary, "wait", cleanedContainerID)
  46. out, _, err = runCommandWithOutput(runCmd)
  47. if err != nil {
  48. c.Fatalf(out, err)
  49. }
  50. endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
  51. _, body, err := sockRequest("POST", endpoint, nil)
  52. if err == nil {
  53. c.Fatalf("resize should fail when container is not started")
  54. }
  55. if !strings.Contains(string(body), "Cannot resize container") && !strings.Contains(string(body), cleanedContainerID) {
  56. c.Fatalf("resize should fail with message 'Cannot resize container' but instead received %s", string(body))
  57. }
  58. }