docker_api_resize_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package main
  2. import (
  3. "context"
  4. "net/http"
  5. "strings"
  6. "github.com/docker/docker/api/types"
  7. "github.com/docker/docker/client"
  8. "github.com/docker/docker/integration-cli/checker"
  9. "github.com/docker/docker/integration-cli/request"
  10. "github.com/go-check/check"
  11. )
  12. func (s *DockerSuite) TestResizeAPIResponse(c *check.C) {
  13. out := runSleepingContainer(c, "-d")
  14. cleanedContainerID := strings.TrimSpace(out)
  15. cli, err := client.NewEnvClient()
  16. c.Assert(err, checker.IsNil)
  17. defer cli.Close()
  18. options := types.ResizeOptions{
  19. Height: 40,
  20. Width: 40,
  21. }
  22. err = cli.ContainerResize(context.Background(), cleanedContainerID, options)
  23. c.Assert(err, check.IsNil)
  24. }
  25. func (s *DockerSuite) TestResizeAPIHeightWidthNoInt(c *check.C) {
  26. out := runSleepingContainer(c, "-d")
  27. cleanedContainerID := strings.TrimSpace(out)
  28. endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar"
  29. res, _, err := request.Post(endpoint)
  30. c.Assert(res.StatusCode, check.Equals, http.StatusBadRequest)
  31. c.Assert(err, check.IsNil)
  32. }
  33. func (s *DockerSuite) TestResizeAPIResponseWhenContainerNotStarted(c *check.C) {
  34. out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
  35. cleanedContainerID := strings.TrimSpace(out)
  36. // make sure the exited container is not running
  37. dockerCmd(c, "wait", cleanedContainerID)
  38. cli, err := client.NewEnvClient()
  39. c.Assert(err, checker.IsNil)
  40. defer cli.Close()
  41. options := types.ResizeOptions{
  42. Height: 40,
  43. Width: 40,
  44. }
  45. err = cli.ContainerResize(context.Background(), cleanedContainerID, options)
  46. c.Assert(err.Error(), checker.Contains, "is not running")
  47. }