docker_api_resize_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. status, _, err := sockRequest("POST", endpoint, nil)
  17. c.Assert(status, check.Equals, http.StatusOK)
  18. c.Assert(err, check.IsNil)
  19. }
  20. func (s *DockerSuite) TestResizeApiHeightWidthNoInt(c *check.C) {
  21. runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
  22. out, _, err := runCommandWithOutput(runCmd)
  23. if err != nil {
  24. c.Fatalf(out, err)
  25. }
  26. cleanedContainerID := strings.TrimSpace(out)
  27. endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar"
  28. status, _, err := sockRequest("POST", endpoint, nil)
  29. c.Assert(status, check.Equals, http.StatusInternalServerError)
  30. c.Assert(err, check.IsNil)
  31. }
  32. func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) {
  33. runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
  34. out, _, err := runCommandWithOutput(runCmd)
  35. if err != nil {
  36. c.Fatalf(out, err)
  37. }
  38. cleanedContainerID := strings.TrimSpace(out)
  39. // make sure the exited container is not running
  40. runCmd = exec.Command(dockerBinary, "wait", cleanedContainerID)
  41. out, _, err = runCommandWithOutput(runCmd)
  42. if err != nil {
  43. c.Fatalf(out, err)
  44. }
  45. endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
  46. status, body, err := sockRequest("POST", endpoint, nil)
  47. c.Assert(status, check.Equals, http.StatusInternalServerError)
  48. c.Assert(err, check.IsNil)
  49. if !strings.Contains(string(body), "Cannot resize container") && !strings.Contains(string(body), cleanedContainerID) {
  50. c.Fatalf("resize should fail with message 'Cannot resize container' but instead received %s", string(body))
  51. }
  52. }