use of checkers on docker_cli_rm_test.go

Signed-off-by: Yuan Sun <sunyuan3@huawei.com>
This commit is contained in:
Yuan Sun 2015-10-19 10:42:56 +08:00
Родитель bab701c143
Коммит 0780ddc498
1 изменённых файлов: 14 добавлений и 26 удалений

Просмотреть файл

@ -4,6 +4,7 @@ import (
"os" "os"
"strings" "strings"
"github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check" "github.com/go-check/check"
) )
@ -13,9 +14,8 @@ func (s *DockerSuite) TestRmContainerWithRemovedVolume(c *check.C) {
dockerCmd(c, "run", "--name", "losemyvolumes", "-v", "/tmp/testing:/test", "busybox", "true") dockerCmd(c, "run", "--name", "losemyvolumes", "-v", "/tmp/testing:/test", "busybox", "true")
if err := os.Remove("/tmp/testing"); err != nil { err := os.Remove("/tmp/testing")
c.Fatal(err) c.Assert(err, check.IsNil)
}
dockerCmd(c, "rm", "-v", "losemyvolumes") dockerCmd(c, "rm", "-v", "losemyvolumes")
} }
@ -31,9 +31,8 @@ func (s *DockerSuite) TestRmRunningContainer(c *check.C) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
createRunningContainer(c, "foo") createRunningContainer(c, "foo")
if _, _, err := dockerCmdWithError("rm", "foo"); err == nil { _, _, err := dockerCmdWithError("rm", "foo")
c.Fatalf("Expected error, can't rm a running container") c.Assert(err, checker.NotNil, check.Commentf("Expected error, can't rm a running container"))
}
} }
func (s *DockerSuite) TestRmForceRemoveRunningContainer(c *check.C) { func (s *DockerSuite) TestRmForceRemoveRunningContainer(c *check.C) {
@ -55,31 +54,20 @@ func (s *DockerSuite) TestRmContainerOrphaning(c *check.C) {
// build first dockerfile // build first dockerfile
img1, err := buildImage(img, dockerfile1, true) img1, err := buildImage(img, dockerfile1, true)
if err != nil { c.Assert(err, check.IsNil, check.Commentf("Could not build image %s", img))
c.Fatalf("Could not build image %s: %v", img, err)
}
// run container on first image // run container on first image
if out, _, err := dockerCmdWithError("run", img); err != nil { dockerCmd(c, "run", img)
c.Fatalf("Could not run image %s: %v: %s", img, err, out)
}
// rebuild dockerfile with a small addition at the end // rebuild dockerfile with a small addition at the end
if _, err := buildImage(img, dockerfile2, true); err != nil { _, err = buildImage(img, dockerfile2, true)
c.Fatalf("Could not rebuild image %s: %v", img, err) c.Assert(err, check.IsNil, check.Commentf("Could not rebuild image %s", img))
}
// try to remove the image, should error out. // try to remove the image, should error out.
if out, _, err := dockerCmdWithError("rmi", img); err == nil { out, _, err := dockerCmdWithError("rmi", img)
c.Fatalf("Expected to error out removing the image, but succeeded: %s", out) 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 // check if we deleted the first image
out, _, err := dockerCmdWithError("images", "-q", "--no-trunc") out, _ = dockerCmd(c, "images", "-q", "--no-trunc")
if err != nil { c.Assert(out, checker.Contains, img1, check.Commentf("Orphaned container (could not find %q in docker images): %s", img1, out))
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)
}
} }
func (s *DockerSuite) TestRmInvalidContainer(c *check.C) { func (s *DockerSuite) TestRmInvalidContainer(c *check.C) {