docker_api_resize_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package main
  2. import (
  3. "net/http"
  4. "strings"
  5. "github.com/docker/docker/integration-cli/checker"
  6. "github.com/docker/docker/integration-cli/request"
  7. "github.com/go-check/check"
  8. )
  9. func (s *DockerSuite) TestResizeAPIResponse(c *check.C) {
  10. out := runSleepingContainer(c, "-d")
  11. cleanedContainerID := strings.TrimSpace(out)
  12. endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
  13. status, _, err := request.SockRequest("POST", endpoint, nil, daemonHost())
  14. c.Assert(status, check.Equals, http.StatusOK)
  15. c.Assert(err, check.IsNil)
  16. }
  17. func (s *DockerSuite) TestResizeAPIHeightWidthNoInt(c *check.C) {
  18. out := runSleepingContainer(c, "-d")
  19. cleanedContainerID := strings.TrimSpace(out)
  20. endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar"
  21. status, _, err := request.SockRequest("POST", endpoint, nil, daemonHost())
  22. c.Assert(status, check.Equals, http.StatusInternalServerError)
  23. c.Assert(err, check.IsNil)
  24. }
  25. func (s *DockerSuite) TestResizeAPIResponseWhenContainerNotStarted(c *check.C) {
  26. out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
  27. cleanedContainerID := strings.TrimSpace(out)
  28. // make sure the exited container is not running
  29. dockerCmd(c, "wait", cleanedContainerID)
  30. endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
  31. status, body, err := request.SockRequest("POST", endpoint, nil, daemonHost())
  32. c.Assert(status, check.Equals, http.StatusInternalServerError)
  33. c.Assert(err, check.IsNil)
  34. c.Assert(getErrorMessage(c, body), checker.Contains, "is not running", check.Commentf("resize should fail with message 'Container is not running'"))
  35. }