2014-10-23 20:30:18 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-04-13 17:30:07 +00:00
|
|
|
"net/http"
|
2014-10-23 20:30:18 +00:00
|
|
|
"os/exec"
|
|
|
|
"strings"
|
2015-04-18 16:46:47 +00:00
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2014-10-23 20:30:18 +00:00
|
|
|
)
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestResizeApiResponse(c *check.C) {
|
2014-10-24 04:27:09 +00:00
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
|
2014-10-23 20:30:18 +00:00
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf(out, err)
|
2014-10-23 20:30:18 +00:00
|
|
|
}
|
2015-04-06 13:21:18 +00:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2014-10-23 20:30:18 +00:00
|
|
|
|
|
|
|
endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
|
2015-04-11 21:49:14 +00:00
|
|
|
_, _, err = sockRequest("POST", endpoint, nil)
|
2014-10-23 20:30:18 +00:00
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("resize Request failed %v", err)
|
2014-10-23 20:30:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestResizeApiHeightWidthNoInt(c *check.C) {
|
2015-04-13 06:36:04 +00:00
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
|
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf(out, err)
|
2015-04-13 06:36:04 +00:00
|
|
|
}
|
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar"
|
2015-04-13 17:30:07 +00:00
|
|
|
status, _, err := sockRequest("POST", endpoint, nil)
|
2015-04-13 06:36:04 +00:00
|
|
|
if err == nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal("Expected resize Request to fail")
|
2015-04-13 06:36:04 +00:00
|
|
|
}
|
2015-04-13 17:30:07 +00:00
|
|
|
if status != http.StatusInternalServerError {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("Status expected %d, got %d", http.StatusInternalServerError, status)
|
2015-04-13 17:30:07 +00:00
|
|
|
}
|
2015-04-13 06:36:04 +00:00
|
|
|
}
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) {
|
2014-10-23 20:30:18 +00:00
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
|
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf(out, err)
|
2014-10-23 20:30:18 +00:00
|
|
|
}
|
2015-04-06 13:21:18 +00:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2014-10-23 20:30:18 +00:00
|
|
|
|
2015-04-10 07:09:26 +00:00
|
|
|
// make sure the exited container is not running
|
2014-10-23 20:30:18 +00:00
|
|
|
runCmd = exec.Command(dockerBinary, "wait", cleanedContainerID)
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf(out, err)
|
2014-10-23 20:30:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
|
2015-04-11 21:49:14 +00:00
|
|
|
_, body, err := sockRequest("POST", endpoint, nil)
|
2014-10-23 20:30:18 +00:00
|
|
|
if err == nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("resize should fail when container is not started")
|
2014-10-23 20:30:18 +00:00
|
|
|
}
|
|
|
|
if !strings.Contains(string(body), "Cannot resize container") && !strings.Contains(string(body), cleanedContainerID) {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("resize should fail with message 'Cannot resize container' but instead received %s", string(body))
|
2014-10-23 20:30:18 +00:00
|
|
|
}
|
|
|
|
}
|