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