docker_api_resize_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
  9. cleanedContainerID := strings.TrimSpace(out)
  10. endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
  11. status, _, err := sockRequest("POST", endpoint, nil)
  12. c.Assert(status, check.Equals, http.StatusOK)
  13. c.Assert(err, check.IsNil)
  14. }
  15. func (s *DockerSuite) TestResizeApiHeightWidthNoInt(c *check.C) {
  16. out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
  17. cleanedContainerID := strings.TrimSpace(out)
  18. endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar"
  19. status, _, err := sockRequest("POST", endpoint, nil)
  20. c.Assert(status, check.Equals, http.StatusInternalServerError)
  21. c.Assert(err, check.IsNil)
  22. }
  23. func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) {
  24. out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
  25. cleanedContainerID := strings.TrimSpace(out)
  26. // make sure the exited container is not running
  27. dockerCmd(c, "wait", cleanedContainerID)
  28. endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
  29. status, body, err := sockRequest("POST", endpoint, nil)
  30. c.Assert(status, check.Equals, http.StatusInternalServerError)
  31. c.Assert(err, check.IsNil)
  32. if !strings.Contains(string(body), "Cannot resize container") && !strings.Contains(string(body), cleanedContainerID) {
  33. c.Fatalf("resize should fail with message 'Cannot resize container' but instead received %s", string(body))
  34. }
  35. }