зеркало из https://github.com/microsoft/docker.git
use of checkers on docker_cli_rm_test.go
Signed-off-by: Yuan Sun <sunyuan3@huawei.com>
This commit is contained in:
Родитель
bab701c143
Коммит
0780ddc498
|
@ -4,6 +4,7 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
"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")
|
||||
|
||||
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")
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче