|
@@ -52,29 +52,20 @@ func (s *DockerSuite) TestExecApiCreateNoValidContentType(c *check.C) {
|
|
func (s *DockerSuite) TestExecAPIStart(c *check.C) {
|
|
func (s *DockerSuite) TestExecAPIStart(c *check.C) {
|
|
dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top")
|
|
dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top")
|
|
|
|
|
|
- createExec := func() string {
|
|
|
|
- _, b, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", "test"), map[string]interface{}{"Cmd": []string{"true"}})
|
|
|
|
- c.Assert(err, check.IsNil, check.Commentf(string(b)))
|
|
|
|
-
|
|
|
|
- createResp := struct {
|
|
|
|
- ID string `json:"Id"`
|
|
|
|
- }{}
|
|
|
|
- c.Assert(json.Unmarshal(b, &createResp), check.IsNil, check.Commentf(string(b)))
|
|
|
|
- return createResp.ID
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
startExec := func(id string, code int) {
|
|
startExec := func(id string, code int) {
|
|
resp, body, err := sockRequestRaw("POST", fmt.Sprintf("/exec/%s/start", id), strings.NewReader(`{"Detach": true}`), "application/json")
|
|
resp, body, err := sockRequestRaw("POST", fmt.Sprintf("/exec/%s/start", id), strings.NewReader(`{"Detach": true}`), "application/json")
|
|
c.Assert(err, check.IsNil)
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
b, err := readBody(body)
|
|
b, err := readBody(body)
|
|
- c.Assert(err, check.IsNil, check.Commentf(string(b)))
|
|
|
|
- c.Assert(resp.StatusCode, check.Equals, code, check.Commentf(string(b)))
|
|
|
|
|
|
+ comment := check.Commentf("response body: %s", b)
|
|
|
|
+ c.Assert(err, check.IsNil, comment)
|
|
|
|
+ c.Assert(resp.StatusCode, check.Equals, code, comment)
|
|
}
|
|
}
|
|
|
|
|
|
- startExec(createExec(), http.StatusOK)
|
|
|
|
|
|
+ id := createExec(c, "test")
|
|
|
|
+ startExec(id, http.StatusOK)
|
|
|
|
|
|
- id := createExec()
|
|
|
|
|
|
+ id = createExec(c, "test")
|
|
dockerCmd(c, "stop", "test")
|
|
dockerCmd(c, "stop", "test")
|
|
|
|
|
|
startExec(id, http.StatusNotFound)
|
|
startExec(id, http.StatusNotFound)
|
|
@@ -83,9 +74,33 @@ func (s *DockerSuite) TestExecAPIStart(c *check.C) {
|
|
startExec(id, http.StatusNotFound)
|
|
startExec(id, http.StatusNotFound)
|
|
|
|
|
|
// make sure exec is created before pausing
|
|
// make sure exec is created before pausing
|
|
- id = createExec()
|
|
|
|
|
|
+ id = createExec(c, "test")
|
|
dockerCmd(c, "pause", "test")
|
|
dockerCmd(c, "pause", "test")
|
|
startExec(id, http.StatusConflict)
|
|
startExec(id, http.StatusConflict)
|
|
dockerCmd(c, "unpause", "test")
|
|
dockerCmd(c, "unpause", "test")
|
|
startExec(id, http.StatusOK)
|
|
startExec(id, http.StatusOK)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func (s *DockerSuite) TestExecAPIStartBackwardsCompatible(c *check.C) {
|
|
|
|
+ dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top")
|
|
|
|
+ id := createExec(c, "test")
|
|
|
|
+
|
|
|
|
+ resp, body, err := sockRequestRaw("POST", fmt.Sprintf("/v1.20/exec/%s/start", id), strings.NewReader(`{"Detach": true}`), "text/plain")
|
|
|
|
+ c.Assert(err, check.IsNil)
|
|
|
|
+
|
|
|
|
+ b, err := readBody(body)
|
|
|
|
+ comment := check.Commentf("response body: %s", b)
|
|
|
|
+ c.Assert(err, check.IsNil, comment)
|
|
|
|
+ c.Assert(resp.StatusCode, check.Equals, http.StatusOK, comment)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func createExec(c *check.C, name string) string {
|
|
|
|
+ _, b, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": []string{"true"}})
|
|
|
|
+ c.Assert(err, check.IsNil, check.Commentf(string(b)))
|
|
|
|
+
|
|
|
|
+ createResp := struct {
|
|
|
|
+ ID string `json:"Id"`
|
|
|
|
+ }{}
|
|
|
|
+ c.Assert(json.Unmarshal(b, &createResp), check.IsNil, check.Commentf(string(b)))
|
|
|
|
+ return createResp.ID
|
|
|
|
+}
|