Browse code

Add test for REST API container rename

Signed-off-by: Hu Keping <hukeping@huawei.com>

Hu Keping authored on 2015/04/24 20:57:04
Showing 1 changed files
... ...
@@ -841,3 +841,22 @@ func (s *DockerSuite) TestStartWithTooLowMemoryLimit(c *check.C) {
841 841
 	c.Assert(status, check.Equals, http.StatusInternalServerError)
842 842
 	c.Assert(strings.Contains(string(b), "Minimum memory limit allowed is 4MB"), check.Equals, true)
843 843
 }
844
+
845
+func (s *DockerSuite) TestContainerApiRename(c *check.C) {
846
+	runCmd := exec.Command(dockerBinary, "run", "--name", "first_name", "-d", "busybox", "sh")
847
+	out, _, err := runCommandWithOutput(runCmd)
848
+	c.Assert(err, check.IsNil)
849
+
850
+	containerID := strings.TrimSpace(out)
851
+	newName := "new_name" + stringid.GenerateRandomID()
852
+	statusCode, _, err := sockRequest("POST", "/containers/"+containerID+"/rename?name="+newName, nil)
853
+
854
+	// 204 No Content is expected, not 200
855
+	c.Assert(statusCode, check.Equals, http.StatusNoContent)
856
+	c.Assert(err, check.IsNil)
857
+
858
+	name, err := inspectField(containerID, "Name")
859
+	if name != "/"+newName {
860
+		c.Fatalf("Failed to rename container, expected %v, got %v. Container rename API failed", newName, name)
861
+	}
862
+}