Add tests for API container delete
Signed-off-by: Antonio Murdaca <me@runcom.ninja>
This commit is contained in:
parent
3fcf387d52
commit
8771cafab6
|
@ -6,6 +6,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -1040,3 +1041,112 @@ func (s *DockerSuite) TestContainerApiCopyContainerNotFound(c *check.C) {
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
c.Assert(status, check.Equals, http.StatusNotFound)
|
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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"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) {
|
func (s *DockerSuite) TestRmForceRemoveRunningContainer(c *check.C) {
|
||||||
|
|
||||||
createRunningContainer(c, "foo")
|
createRunningContainer(c, "foo")
|
||||||
|
|
Loading…
Reference in New Issue