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