integration-cli/docker_cli_rm_test.go
39103e72
 package main
 
 import (
07fd1732
 	"io/ioutil"
39103e72
 	"os"
dc944ea7
 
0780ddc4
 	"github.com/docker/docker/pkg/integration/checker"
dc944ea7
 	"github.com/go-check/check"
39103e72
 )
 
dc944ea7
 func (s *DockerSuite) TestRmContainerWithRemovedVolume(c *check.C) {
 	testRequires(c, SameHostDaemon)
70407ce4
 
382c96ee
 	prefix, slash := getPrefixAndSlashFromDaemonPlatform()
07fd1732
 
 	tempDir, err := ioutil.TempDir("", "test-rm-container-with-removed-volume-")
 	if err != nil {
 		c.Fatalf("failed to create temporary directory: %s", tempDir)
 	}
 	defer os.RemoveAll(tempDir)
39103e72
 
07fd1732
 	dockerCmd(c, "run", "--name", "losemyvolumes", "-v", tempDir+":"+prefix+slash+"test", "busybox", "true")
 
 	err = os.RemoveAll(tempDir)
0780ddc4
 	c.Assert(err, check.IsNil)
39103e72
 
71868228
 	dockerCmd(c, "rm", "-v", "losemyvolumes")
39103e72
 }
fcbc717f
 
dc944ea7
 func (s *DockerSuite) TestRmContainerWithVolume(c *check.C) {
382c96ee
 	prefix, slash := getPrefixAndSlashFromDaemonPlatform()
07fd1732
 
 	dockerCmd(c, "run", "--name", "foo", "-v", prefix+slash+"srv", "busybox", "true")
70407ce4
 
71868228
 	dockerCmd(c, "rm", "-v", "foo")
fcbc717f
 }
 
07fd1732
 func (s *DockerSuite) TestRmContainerRunning(c *check.C) {
dc944ea7
 	createRunningContainer(c, "foo")
fcbc717f
 
0780ddc4
 	_, _, err := dockerCmdWithError("rm", "foo")
 	c.Assert(err, checker.NotNil, check.Commentf("Expected error, can't rm a running container"))
d689a5e1
 }
 
07fd1732
 func (s *DockerSuite) TestRmContainerForceRemoveRunning(c *check.C) {
dc944ea7
 	createRunningContainer(c, "foo")
d689a5e1
 
 	// Stop then remove with -s
71868228
 	dockerCmd(c, "rm", "-f", "foo")
d689a5e1
 }
 
dc944ea7
 func (s *DockerSuite) TestRmContainerOrphaning(c *check.C) {
69f9d488
 	dockerfile1 := `FROM busybox:latest
07fd1732
 	ENTRYPOINT ["true"]`
69f9d488
 	img := "test-container-orphaning"
 	dockerfile2 := `FROM busybox:latest
07fd1732
 	ENTRYPOINT ["true"]
69f9d488
 	MAINTAINER Integration Tests`
 
 	// build first dockerfile
 	img1, err := buildImage(img, dockerfile1, true)
0780ddc4
 	c.Assert(err, check.IsNil, check.Commentf("Could not build image %s", img))
69f9d488
 	// run container on first image
0780ddc4
 	dockerCmd(c, "run", img)
69f9d488
 	// rebuild dockerfile with a small addition at the end
0780ddc4
 	_, err = buildImage(img, dockerfile2, true)
 	c.Assert(err, check.IsNil, check.Commentf("Could not rebuild image %s", img))
0bbc9f1d
 	// try to remove the image, should not error out.
0780ddc4
 	out, _, err := dockerCmdWithError("rmi", img)
0bbc9f1d
 	c.Assert(err, check.IsNil, check.Commentf("Expected to removing the image, but failed: %s", out))
71868228
 
69f9d488
 	// check if we deleted the first image
0780ddc4
 	out, _ = dockerCmd(c, "images", "-q", "--no-trunc")
 	c.Assert(out, checker.Contains, img1, check.Commentf("Orphaned container (could not find %q in docker images): %s", img1, out))
 
69f9d488
 }
 
dc944ea7
 func (s *DockerSuite) TestRmInvalidContainer(c *check.C) {
894266c1
 	out, _, err := dockerCmdWithError("rm", "unknown")
 	c.Assert(err, checker.NotNil, check.Commentf("Expected error on rm unknown container, got none"))
 	c.Assert(out, checker.Contains, "No such container")
69f9d488
 }
 
dc944ea7
 func createRunningContainer(c *check.C, name string) {
07fd1732
 	runSleepingContainer(c, "-dt", "--name", name)
fcbc717f
 }