From 68e9c07850c95ded1e0a8adda39a8efe68e1c0ee Mon Sep 17 00:00:00 2001 From: Srini Brahmaroutu Date: Mon, 27 Apr 2015 18:55:11 +0000 Subject: [PATCH] Restapi for stop fails if ?t=int not present Signed-off-by: Srini Brahmaroutu --- api/server/server.go | 5 +---- integration-cli/docker_api_containers_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/api/server/server.go b/api/server/server.go index ab236f876f..49339383c8 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -1040,10 +1040,7 @@ func (s *Server) postContainersStop(version version.Version, w http.ResponseWrit return fmt.Errorf("Missing parameter") } - seconds, err := strconv.Atoi(r.Form.Get("t")) - if err != nil { - return err - } + seconds, _ := strconv.Atoi(r.Form.Get("t")) if err := s.daemon.ContainerStop(vars["name"], seconds); err != nil { if err.Error() == "Container already stopped" { diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index e4e3a4e9da..8fa22c4be2 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -1202,3 +1202,22 @@ func (s *DockerSuite) TestContainersApiChunkedEncoding(c *check.C) { c.Fatalf("got incorrect bind spec, wanted %s, got: %s", expected, binds[0]) } } + +func (s *DockerSuite) TestPostContainerStop(c *check.C) { + runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top") + out, _, err := runCommandWithOutput(runCmd) + c.Assert(err, check.IsNil) + + containerID := strings.TrimSpace(out) + c.Assert(waitRun(containerID), check.IsNil) + + statusCode, _, err := sockRequest("POST", "/containers/"+containerID+"/stop", nil) + + // 204 No Content is expected, not 200 + c.Assert(statusCode, check.Equals, http.StatusNoContent) + c.Assert(err, check.IsNil) + + if err := waitInspect(containerID, "{{ .State.Running }}", "false", 5); err != nil { + c.Fatal(err) + } +}