github.com/ld86/docker@v1.7.1-rc3/integration-cli/docker_api_resize_test.go (about)

     1  package main
     2  
     3  import (
     4  	"net/http"
     5  	"os/exec"
     6  	"strings"
     7  
     8  	"github.com/go-check/check"
     9  )
    10  
    11  func (s *DockerSuite) TestResizeApiResponse(c *check.C) {
    12  	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
    13  	out, _, err := runCommandWithOutput(runCmd)
    14  	if err != nil {
    15  		c.Fatalf(out, err)
    16  	}
    17  	cleanedContainerID := strings.TrimSpace(out)
    18  
    19  	endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
    20  	status, _, err := sockRequest("POST", endpoint, nil)
    21  	c.Assert(status, check.Equals, http.StatusOK)
    22  	c.Assert(err, check.IsNil)
    23  }
    24  
    25  func (s *DockerSuite) TestResizeApiHeightWidthNoInt(c *check.C) {
    26  	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
    27  	out, _, err := runCommandWithOutput(runCmd)
    28  	if err != nil {
    29  		c.Fatalf(out, err)
    30  	}
    31  	cleanedContainerID := strings.TrimSpace(out)
    32  
    33  	endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar"
    34  	status, _, err := sockRequest("POST", endpoint, nil)
    35  	c.Assert(status, check.Equals, http.StatusInternalServerError)
    36  	c.Assert(err, check.IsNil)
    37  }
    38  
    39  func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) {
    40  	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
    41  	out, _, err := runCommandWithOutput(runCmd)
    42  	if err != nil {
    43  		c.Fatalf(out, err)
    44  	}
    45  	cleanedContainerID := strings.TrimSpace(out)
    46  
    47  	// make sure the exited container is not running
    48  	runCmd = exec.Command(dockerBinary, "wait", cleanedContainerID)
    49  	out, _, err = runCommandWithOutput(runCmd)
    50  	if err != nil {
    51  		c.Fatalf(out, err)
    52  	}
    53  
    54  	endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
    55  	status, body, err := sockRequest("POST", endpoint, nil)
    56  	c.Assert(status, check.Equals, http.StatusInternalServerError)
    57  	c.Assert(err, check.IsNil)
    58  
    59  	if !strings.Contains(string(body), "Cannot resize container") && !strings.Contains(string(body), cleanedContainerID) {
    60  		c.Fatalf("resize should fail with message 'Cannot resize container' but instead received %s", string(body))
    61  	}
    62  }