1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Use checker Assert for integration-cli/docker_api_exec_test.go

Partially fix issue #16756

Signed-off-by: Wen Cheng Ma <wenchma@cn.ibm.com>
This commit is contained in:
Wen Cheng Ma 2015-11-20 15:03:34 +08:00
parent 7a1b05ccce
commit 1814a1dac5

View file

@ -9,6 +9,7 @@ import (
"net/http"
"strings"
"github.com/docker/docker/pkg/integration/checker"
"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")
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) {
@ -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")
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)
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) {
@ -56,12 +55,11 @@ func (s *DockerSuite) TestExecApiCreateContainerPaused(c *check.C) {
dockerCmd(c, "pause", name)
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) {
@ -69,12 +67,12 @@ func (s *DockerSuite) TestExecAPIStart(c *check.C) {
startExec := func(id string, code int) {
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)
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")
@ -101,21 +99,21 @@ func (s *DockerSuite) TestExecAPIStartBackwardsCompatible(c *check.C) {
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)
c.Assert(err, checker.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)
c.Assert(err, checker.IsNil, comment)
c.Assert(resp.StatusCode, checker.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)))
c.Assert(err, checker.IsNil, check.Commentf(string(b)))
createResp := struct {
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
}