docker_api_resize_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package main
  2. import (
  3. "net/http"
  4. "strings"
  5. "github.com/go-check/check"
  6. )
  7. func (s *DockerSuite) TestResizeApiResponse(c *check.C) {
  8. testRequires(c, DaemonIsLinux)
  9. out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
  10. cleanedContainerID := strings.TrimSpace(out)
  11. endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
  12. status, _, err := sockRequest("POST", endpoint, nil)
  13. c.Assert(status, check.Equals, http.StatusOK)
  14. c.Assert(err, check.IsNil)
  15. }
  16. func (s *DockerSuite) TestResizeApiHeightWidthNoInt(c *check.C) {
  17. testRequires(c, DaemonIsLinux)
  18. out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
  19. cleanedContainerID := strings.TrimSpace(out)
  20. endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar"
  21. status, _, err := sockRequest("POST", endpoint, nil)
  22. c.Assert(status, check.Equals, http.StatusInternalServerError)
  23. c.Assert(err, check.IsNil)
  24. }
  25. func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) {
  26. testRequires(c, DaemonIsLinux)
  27. out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
  28. cleanedContainerID := strings.TrimSpace(out)
  29. // make sure the exited container is not running
  30. dockerCmd(c, "wait", cleanedContainerID)
  31. endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
  32. status, body, err := sockRequest("POST", endpoint, nil)
  33. c.Assert(status, check.Equals, http.StatusInternalServerError)
  34. c.Assert(err, check.IsNil)
  35. if !strings.Contains(string(body), "Cannot resize container") && !strings.Contains(string(body), cleanedContainerID) {
  36. c.Fatalf("resize should fail with message 'Cannot resize container' but instead received %s", string(body))
  37. }
  38. }