|
@@ -9,6 +9,7 @@ import (
|
|
"net/http"
|
|
"net/http"
|
|
"strings"
|
|
"strings"
|
|
|
|
|
|
|
|
+ "github.com/docker/docker/pkg/integration/checker"
|
|
"github.com/go-check/check"
|
|
"github.com/go-check/check"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -19,12 +20,11 @@ func (s *DockerSuite) TestExecApiCreateNoCmd(c *check.C) {
|
|
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
|
|
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
|
|
|
|
|
|
status, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": nil})
|
|
status, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": nil})
|
|
- c.Assert(err, check.IsNil)
|
|
|
|
- c.Assert(status, check.Equals, http.StatusInternalServerError)
|
|
|
|
|
|
+ c.Assert(err, checker.IsNil)
|
|
|
|
+ c.Assert(status, checker.Equals, http.StatusInternalServerError)
|
|
|
|
|
|
- if !bytes.Contains(body, []byte("No exec command specified")) {
|
|
|
|
- c.Fatalf("Expected message when creating exec command with no Cmd specified")
|
|
|
|
- }
|
|
|
|
|
|
+ comment := check.Commentf("Expected message when creating exec command with no Cmd specified")
|
|
|
|
+ c.Assert(string(body), checker.Contains, "No exec command specified", comment)
|
|
}
|
|
}
|
|
|
|
|
|
func (s *DockerSuite) TestExecApiCreateNoValidContentType(c *check.C) {
|
|
func (s *DockerSuite) TestExecApiCreateNoValidContentType(c *check.C) {
|
|
@@ -38,15 +38,14 @@ func (s *DockerSuite) TestExecApiCreateNoValidContentType(c *check.C) {
|
|
}
|
|
}
|
|
|
|
|
|
res, body, err := sockRequestRaw("POST", fmt.Sprintf("/containers/%s/exec", name), jsonData, "text/plain")
|
|
res, body, err := sockRequestRaw("POST", fmt.Sprintf("/containers/%s/exec", name), jsonData, "text/plain")
|
|
- c.Assert(err, check.IsNil)
|
|
|
|
- c.Assert(res.StatusCode, check.Equals, http.StatusInternalServerError)
|
|
|
|
|
|
+ c.Assert(err, checker.IsNil)
|
|
|
|
+ c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError)
|
|
|
|
|
|
b, err := readBody(body)
|
|
b, err := readBody(body)
|
|
- c.Assert(err, check.IsNil)
|
|
|
|
|
|
+ c.Assert(err, checker.IsNil)
|
|
|
|
|
|
- if !bytes.Contains(b, []byte("Content-Type specified")) {
|
|
|
|
- c.Fatalf("Expected message when creating exec command with invalid Content-Type specified")
|
|
|
|
- }
|
|
|
|
|
|
+ comment := check.Commentf("Expected message when creating exec command with invalid Content-Type specified")
|
|
|
|
+ c.Assert(string(b), checker.Contains, "Content-Type specified", comment)
|
|
}
|
|
}
|
|
|
|
|
|
func (s *DockerSuite) TestExecApiCreateContainerPaused(c *check.C) {
|
|
func (s *DockerSuite) TestExecApiCreateContainerPaused(c *check.C) {
|
|
@@ -56,12 +55,11 @@ func (s *DockerSuite) TestExecApiCreateContainerPaused(c *check.C) {
|
|
|
|
|
|
dockerCmd(c, "pause", name)
|
|
dockerCmd(c, "pause", name)
|
|
status, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": []string{"true"}})
|
|
status, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": []string{"true"}})
|
|
- c.Assert(err, check.IsNil)
|
|
|
|
- c.Assert(status, check.Equals, http.StatusConflict)
|
|
|
|
|
|
+ c.Assert(err, checker.IsNil)
|
|
|
|
+ c.Assert(status, checker.Equals, http.StatusConflict)
|
|
|
|
|
|
- if !bytes.Contains(body, []byte("Container "+name+" is paused, unpause the container before exec")) {
|
|
|
|
- c.Fatalf("Expected message when creating exec command with Container %s is paused", name)
|
|
|
|
- }
|
|
|
|
|
|
+ comment := check.Commentf("Expected message when creating exec command with Container s% is paused", name)
|
|
|
|
+ c.Assert(string(body), checker.Contains, "Container "+name+" is paused, unpause the container before exec", comment)
|
|
}
|
|
}
|
|
|
|
|
|
func (s *DockerSuite) TestExecAPIStart(c *check.C) {
|
|
func (s *DockerSuite) TestExecAPIStart(c *check.C) {
|
|
@@ -69,12 +67,12 @@ func (s *DockerSuite) TestExecAPIStart(c *check.C) {
|
|
|
|
|
|
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, checker.IsNil)
|
|
|
|
|
|
b, err := readBody(body)
|
|
b, err := readBody(body)
|
|
comment := check.Commentf("response body: %s", b)
|
|
comment := check.Commentf("response body: %s", b)
|
|
- c.Assert(err, check.IsNil, comment)
|
|
|
|
- c.Assert(resp.StatusCode, check.Equals, code, comment)
|
|
|
|
|
|
+ c.Assert(err, checker.IsNil, comment)
|
|
|
|
+ c.Assert(resp.StatusCode, checker.Equals, code, comment)
|
|
}
|
|
}
|
|
|
|
|
|
id := createExec(c, "test")
|
|
id := createExec(c, "test")
|
|
@@ -101,21 +99,21 @@ func (s *DockerSuite) TestExecAPIStartBackwardsCompatible(c *check.C) {
|
|
id := createExec(c, "test")
|
|
id := createExec(c, "test")
|
|
|
|
|
|
resp, body, err := sockRequestRaw("POST", fmt.Sprintf("/v1.20/exec/%s/start", id), strings.NewReader(`{"Detach": true}`), "text/plain")
|
|
resp, body, err := sockRequestRaw("POST", fmt.Sprintf("/v1.20/exec/%s/start", id), strings.NewReader(`{"Detach": true}`), "text/plain")
|
|
- c.Assert(err, check.IsNil)
|
|
|
|
|
|
+ c.Assert(err, checker.IsNil)
|
|
|
|
|
|
b, err := readBody(body)
|
|
b, err := readBody(body)
|
|
comment := check.Commentf("response body: %s", b)
|
|
comment := check.Commentf("response body: %s", b)
|
|
- c.Assert(err, check.IsNil, comment)
|
|
|
|
- c.Assert(resp.StatusCode, check.Equals, http.StatusOK, comment)
|
|
|
|
|
|
+ c.Assert(err, checker.IsNil, comment)
|
|
|
|
+ c.Assert(resp.StatusCode, checker.Equals, http.StatusOK, comment)
|
|
}
|
|
}
|
|
|
|
|
|
func createExec(c *check.C, name string) string {
|
|
func createExec(c *check.C, name string) string {
|
|
_, b, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": []string{"true"}})
|
|
_, 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)))
|
|
|
|
|
|
+ c.Assert(err, checker.IsNil, check.Commentf(string(b)))
|
|
|
|
|
|
createResp := struct {
|
|
createResp := struct {
|
|
ID string `json:"Id"`
|
|
ID string `json:"Id"`
|
|
}{}
|
|
}{}
|
|
- c.Assert(json.Unmarshal(b, &createResp), check.IsNil, check.Commentf(string(b)))
|
|
|
|
|
|
+ c.Assert(json.Unmarshal(b, &createResp), checker.IsNil, check.Commentf(string(b)))
|
|
return createResp.ID
|
|
return createResp.ID
|
|
}
|
|
}
|