78a272ce |
package main
import ( |
27fccdba |
"net/http" |
78a272ce |
"os/exec"
"strings" |
dc944ea7 |
"github.com/go-check/check" |
78a272ce |
)
|
dc944ea7 |
func (s *DockerSuite) TestResizeApiResponse(c *check.C) { |
91fb9b2f |
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top") |
78a272ce |
out, _, err := runCommandWithOutput(runCmd)
if err != nil { |
dc944ea7 |
c.Fatalf(out, err) |
78a272ce |
} |
475c6531 |
cleanedContainerID := strings.TrimSpace(out) |
78a272ce |
endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40" |
c7845e27 |
status, _, err := sockRequest("POST", endpoint, nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil) |
78a272ce |
}
|
dc944ea7 |
func (s *DockerSuite) TestResizeApiHeightWidthNoInt(c *check.C) { |
3341f3a3 |
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
if err != nil { |
dc944ea7 |
c.Fatalf(out, err) |
3341f3a3 |
}
cleanedContainerID := strings.TrimSpace(out)
endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar" |
27fccdba |
status, _, err := sockRequest("POST", endpoint, nil) |
c7845e27 |
c.Assert(status, check.Equals, http.StatusInternalServerError)
c.Assert(err, check.IsNil) |
3341f3a3 |
}
|
dc944ea7 |
func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) { |
78a272ce |
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
out, _, err := runCommandWithOutput(runCmd)
if err != nil { |
dc944ea7 |
c.Fatalf(out, err) |
78a272ce |
} |
475c6531 |
cleanedContainerID := strings.TrimSpace(out) |
78a272ce |
|
4ddc721f |
// make sure the exited container is not running |
78a272ce |
runCmd = exec.Command(dockerBinary, "wait", cleanedContainerID)
out, _, err = runCommandWithOutput(runCmd)
if err != nil { |
dc944ea7 |
c.Fatalf(out, err) |
78a272ce |
}
endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40" |
c7845e27 |
status, body, err := sockRequest("POST", endpoint, nil)
c.Assert(status, check.Equals, http.StatusInternalServerError)
c.Assert(err, check.IsNil)
|
78a272ce |
if !strings.Contains(string(body), "Cannot resize container") && !strings.Contains(string(body), cleanedContainerID) { |
dc944ea7 |
c.Fatalf("resize should fail with message 'Cannot resize container' but instead received %s", string(body)) |
78a272ce |
}
} |