Browse code

Restapi for stop fails if ?t=int not present Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>

Srini Brahmaroutu authored on 2015/04/28 03:55:11
Showing 2 changed files
... ...
@@ -1040,10 +1040,7 @@ func (s *Server) postContainersStop(version version.Version, w http.ResponseWrit
1040 1040
 		return fmt.Errorf("Missing parameter")
1041 1041
 	}
1042 1042
 
1043
-	seconds, err := strconv.Atoi(r.Form.Get("t"))
1044
-	if err != nil {
1045
-		return err
1046
-	}
1043
+	seconds, _ := strconv.Atoi(r.Form.Get("t"))
1047 1044
 
1048 1045
 	if err := s.daemon.ContainerStop(vars["name"], seconds); err != nil {
1049 1046
 		if err.Error() == "Container already stopped" {
... ...
@@ -1202,3 +1202,22 @@ func (s *DockerSuite) TestContainersApiChunkedEncoding(c *check.C) {
1202 1202
 		c.Fatalf("got incorrect bind spec, wanted %s, got: %s", expected, binds[0])
1203 1203
 	}
1204 1204
 }
1205
+
1206
+func (s *DockerSuite) TestPostContainerStop(c *check.C) {
1207
+	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
1208
+	out, _, err := runCommandWithOutput(runCmd)
1209
+	c.Assert(err, check.IsNil)
1210
+
1211
+	containerID := strings.TrimSpace(out)
1212
+	c.Assert(waitRun(containerID), check.IsNil)
1213
+
1214
+	statusCode, _, err := sockRequest("POST", "/containers/"+containerID+"/stop", nil)
1215
+
1216
+	// 204 No Content is expected, not 200
1217
+	c.Assert(statusCode, check.Equals, http.StatusNoContent)
1218
+	c.Assert(err, check.IsNil)
1219
+
1220
+	if err := waitInspect(containerID, "{{ .State.Running  }}", "false", 5); err != nil {
1221
+		c.Fatal(err)
1222
+	}
1223
+}