Skip to content

Commit

Permalink
use of checkers on docker_cli_rm_test.go
Browse files Browse the repository at this point in the history
Signed-off-by: Yuan Sun <sunyuan3@huawei.com>
  • Loading branch information
sunyuan3 committed Oct 19, 2015
1 parent bab701c commit 0780ddc
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions integration-cli/docker_cli_rm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"
"strings"

"github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check"
)

Expand All @@ -13,9 +14,8 @@ func (s *DockerSuite) TestRmContainerWithRemovedVolume(c *check.C) {

dockerCmd(c, "run", "--name", "losemyvolumes", "-v", "/tmp/testing:/test", "busybox", "true")

if err := os.Remove("/tmp/testing"); err != nil {
c.Fatal(err)
}
err := os.Remove("/tmp/testing")
c.Assert(err, check.IsNil)

dockerCmd(c, "rm", "-v", "losemyvolumes")
}
Expand All @@ -31,9 +31,8 @@ func (s *DockerSuite) TestRmRunningContainer(c *check.C) {
testRequires(c, DaemonIsLinux)
createRunningContainer(c, "foo")

if _, _, err := dockerCmdWithError("rm", "foo"); err == nil {
c.Fatalf("Expected error, can't rm a running container")
}
_, _, err := dockerCmdWithError("rm", "foo")
c.Assert(err, checker.NotNil, check.Commentf("Expected error, can't rm a running container"))
}

func (s *DockerSuite) TestRmForceRemoveRunningContainer(c *check.C) {
Expand All @@ -55,31 +54,20 @@ func (s *DockerSuite) TestRmContainerOrphaning(c *check.C) {

// build first dockerfile
img1, err := buildImage(img, dockerfile1, true)
if err != nil {
c.Fatalf("Could not build image %s: %v", img, err)
}
c.Assert(err, check.IsNil, check.Commentf("Could not build image %s", img))
// run container on first image
if out, _, err := dockerCmdWithError("run", img); err != nil {
c.Fatalf("Could not run image %s: %v: %s", img, err, out)
}

dockerCmd(c, "run", img)
// rebuild dockerfile with a small addition at the end
if _, err := buildImage(img, dockerfile2, true); err != nil {
c.Fatalf("Could not rebuild image %s: %v", img, err)
}
_, err = buildImage(img, dockerfile2, true)
c.Assert(err, check.IsNil, check.Commentf("Could not rebuild image %s", img))
// try to remove the image, should error out.
if out, _, err := dockerCmdWithError("rmi", img); err == nil {
c.Fatalf("Expected to error out removing the image, but succeeded: %s", out)
}
out, _, err := dockerCmdWithError("rmi", img)
c.Assert(err, check.NotNil, check.Commentf("Expected to error out removing the image, but succeeded: %s", out))

// check if we deleted the first image
out, _, err := dockerCmdWithError("images", "-q", "--no-trunc")
if err != nil {
c.Fatalf("%v: %s", err, out)
}
if !strings.Contains(out, img1) {
c.Fatalf("Orphaned container (could not find %q in docker images): %s", img1, out)
}
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))

}

func (s *DockerSuite) TestRmInvalidContainer(c *check.C) {
Expand Down

0 comments on commit 0780ddc

Please sign in to comment.