mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Make exec start return proper error codes
Exec start was sending HTTP 500 for every error. Fixed an error where pausing a container and then calling exec start caused the daemon to freeze. Updated API docs which incorrectly showed that a successful exec start was an HTTP 201, in reality it is HTTP 200. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
parent
698e14902a
commit
2d43d93410
12 changed files with 102 additions and 43 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
@ -47,3 +48,44 @@ func (s *DockerSuite) TestExecApiCreateNoValidContentType(c *check.C) {
|
|||
c.Fatalf("Expected message when creating exec command with invalid Content-Type specified")
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecAPIStart(c *check.C) {
|
||||
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) {
|
||||
resp, body, err := sockRequestRaw("POST", fmt.Sprintf("/exec/%s/start", id), strings.NewReader(`{"Detach": true}`), "application/json")
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
b, err := readBody(body)
|
||||
c.Assert(err, check.IsNil, check.Commentf(string(b)))
|
||||
c.Assert(resp.StatusCode, check.Equals, code, check.Commentf(string(b)))
|
||||
}
|
||||
|
||||
startExec(createExec(), http.StatusOK)
|
||||
|
||||
id := createExec()
|
||||
dockerCmd(c, "stop", "test")
|
||||
|
||||
startExec(id, http.StatusNotFound)
|
||||
|
||||
dockerCmd(c, "start", "test")
|
||||
startExec(id, http.StatusNotFound)
|
||||
|
||||
// make sure exec is created before pausing
|
||||
id = createExec()
|
||||
dockerCmd(c, "pause", "test")
|
||||
startExec(id, http.StatusConflict)
|
||||
dockerCmd(c, "unpause", "test")
|
||||
startExec(id, http.StatusOK)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue