github.com/damirazo/docker@v1.9.0/integration-cli/docker_api_resize_test.go (about)

     1  package main
     2  
     3  import (
     4  	"net/http"
     5  	"strings"
     6  
     7  	"github.com/go-check/check"
     8  )
     9  
    10  func (s *DockerSuite) TestResizeApiResponse(c *check.C) {
    11  	testRequires(c, DaemonIsLinux)
    12  	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
    13  	cleanedContainerID := strings.TrimSpace(out)
    14  
    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  
    21  func (s *DockerSuite) TestResizeApiHeightWidthNoInt(c *check.C) {
    22  	testRequires(c, DaemonIsLinux)
    23  	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
    24  	cleanedContainerID := strings.TrimSpace(out)
    25  
    26  	endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar"
    27  	status, _, err := sockRequest("POST", endpoint, nil)
    28  	c.Assert(status, check.Equals, http.StatusInternalServerError)
    29  	c.Assert(err, check.IsNil)
    30  }
    31  
    32  func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) {
    33  	testRequires(c, DaemonIsLinux)
    34  	out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
    35  	cleanedContainerID := strings.TrimSpace(out)
    36  
    37  	// make sure the exited container is not running
    38  	dockerCmd(c, "wait", cleanedContainerID)
    39  
    40  	endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
    41  	status, body, err := sockRequest("POST", endpoint, nil)
    42  	c.Assert(status, check.Equals, http.StatusInternalServerError)
    43  	c.Assert(err, check.IsNil)
    44  
    45  	if !strings.Contains(string(body), "Cannot resize container") && !strings.Contains(string(body), cleanedContainerID) {
    46  		c.Fatalf("resize should fail with message 'Cannot resize container' but instead received %s", string(body))
    47  	}
    48  }