mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #12948 from runcom/api-tests-container-delete
Add tests for API container delete
This commit is contained in:
commit
980c0e8c3b
2 changed files with 110 additions and 11 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -1040,3 +1041,112 @@ func (s *DockerSuite) TestContainerApiCopyContainerNotFound(c *check.C) {
|
|||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusNotFound)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerApiDelete(c *check.C) {
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
id := strings.TrimSpace(out)
|
||||
c.Assert(waitRun(id), check.IsNil)
|
||||
|
||||
stopCmd := exec.Command(dockerBinary, "stop", id)
|
||||
_, err = runCommand(stopCmd)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
status, _, err := sockRequest("DELETE", "/containers/"+id, nil)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerApiDeleteNotExist(c *check.C) {
|
||||
status, body, err := sockRequest("DELETE", "/containers/doesnotexist", nil)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusNotFound)
|
||||
c.Assert(string(body), check.Matches, "no such id: doesnotexist\n")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerApiDeleteForce(c *check.C) {
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
id := strings.TrimSpace(out)
|
||||
c.Assert(waitRun(id), check.IsNil)
|
||||
|
||||
status, _, err := sockRequest("DELETE", "/containers/"+id+"?force=1", nil)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerApiDeleteRemoveLinks(c *check.C) {
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "tlink1", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
id := strings.TrimSpace(out)
|
||||
c.Assert(waitRun(id), check.IsNil)
|
||||
|
||||
runCmd = exec.Command(dockerBinary, "run", "--link", "tlink1:tlink1", "--name", "tlink2", "-d", "busybox", "top")
|
||||
out, _, err = runCommandWithOutput(runCmd)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
id2 := strings.TrimSpace(out)
|
||||
c.Assert(waitRun(id2), check.IsNil)
|
||||
|
||||
links, err := inspectFieldJSON(id2, "HostConfig.Links")
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
if links != "[\"/tlink1:/tlink2/tlink1\"]" {
|
||||
c.Fatal("expected to have links between containers")
|
||||
}
|
||||
|
||||
status, _, err := sockRequest("DELETE", "/containers/tlink2/tlink1?link=1", nil)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusNoContent)
|
||||
|
||||
linksPostRm, err := inspectFieldJSON(id2, "HostConfig.Links")
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
if linksPostRm != "null" {
|
||||
c.Fatal("call to api deleteContainer links should have removed the specified links")
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerApiDeleteConflict(c *check.C) {
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
id := strings.TrimSpace(out)
|
||||
c.Assert(waitRun(id), check.IsNil)
|
||||
|
||||
status, _, err := sockRequest("DELETE", "/containers/"+id, nil)
|
||||
c.Assert(status, check.Equals, http.StatusConflict)
|
||||
c.Assert(err, check.IsNil)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerApiDeleteRemoveVolume(c *check.C) {
|
||||
testRequires(c, SameHostDaemon)
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "-v", "/testvolume", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
id := strings.TrimSpace(out)
|
||||
c.Assert(waitRun(id), check.IsNil)
|
||||
|
||||
vol, err := inspectFieldMap(id, "Volumes", "/testvolume")
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
_, err = os.Stat(vol)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
status, _, err := sockRequest("DELETE", "/containers/"+id+"?v=1&force=1", nil)
|
||||
c.Assert(status, check.Equals, http.StatusNoContent)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
if _, err := os.Stat(vol); !os.IsNotExist(err) {
|
||||
c.Fatalf("expected to get ErrNotExist error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
@ -54,16 +53,6 @@ func (s *DockerSuite) TestRmRunningContainer(c *check.C) {
|
|||
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRmRunningContainerCheckError409(c *check.C) {
|
||||
|
||||
createRunningContainer(c, "foo")
|
||||
|
||||
endpoint := "/containers/foo"
|
||||
status, _, err := sockRequest("DELETE", endpoint, nil)
|
||||
c.Assert(status, check.Equals, http.StatusConflict)
|
||||
c.Assert(err, check.IsNil)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRmForceRemoveRunningContainer(c *check.C) {
|
||||
|
||||
createRunningContainer(c, "foo")
|
||||
|
|
Loading…
Add table
Reference in a new issue