Browse code

use of checkers on docker_cli_rm_test.go

Signed-off-by: Yuan Sun <sunyuan3@huawei.com>

Yuan Sun authored on 2015/10/19 11:42:56
Showing 1 changed files
... ...
@@ -4,6 +4,7 @@ import (
4 4
 	"os"
5 5
 	"strings"
6 6
 
7
+	"github.com/docker/docker/pkg/integration/checker"
7 8
 	"github.com/go-check/check"
8 9
 )
9 10
 
... ...
@@ -13,9 +14,8 @@ func (s *DockerSuite) TestRmContainerWithRemovedVolume(c *check.C) {
13 13
 
14 14
 	dockerCmd(c, "run", "--name", "losemyvolumes", "-v", "/tmp/testing:/test", "busybox", "true")
15 15
 
16
-	if err := os.Remove("/tmp/testing"); err != nil {
17
-		c.Fatal(err)
18
-	}
16
+	err := os.Remove("/tmp/testing")
17
+	c.Assert(err, check.IsNil)
19 18
 
20 19
 	dockerCmd(c, "rm", "-v", "losemyvolumes")
21 20
 }
... ...
@@ -31,9 +31,8 @@ func (s *DockerSuite) TestRmRunningContainer(c *check.C) {
31 31
 	testRequires(c, DaemonIsLinux)
32 32
 	createRunningContainer(c, "foo")
33 33
 
34
-	if _, _, err := dockerCmdWithError("rm", "foo"); err == nil {
35
-		c.Fatalf("Expected error, can't rm a running container")
36
-	}
34
+	_, _, err := dockerCmdWithError("rm", "foo")
35
+	c.Assert(err, checker.NotNil, check.Commentf("Expected error, can't rm a running container"))
37 36
 }
38 37
 
39 38
 func (s *DockerSuite) TestRmForceRemoveRunningContainer(c *check.C) {
... ...
@@ -55,31 +54,20 @@ func (s *DockerSuite) TestRmContainerOrphaning(c *check.C) {
55 55
 
56 56
 	// build first dockerfile
57 57
 	img1, err := buildImage(img, dockerfile1, true)
58
-	if err != nil {
59
-		c.Fatalf("Could not build image %s: %v", img, err)
60
-	}
58
+	c.Assert(err, check.IsNil, check.Commentf("Could not build image %s", img))
61 59
 	// run container on first image
62
-	if out, _, err := dockerCmdWithError("run", img); err != nil {
63
-		c.Fatalf("Could not run image %s: %v: %s", img, err, out)
64
-	}
65
-
60
+	dockerCmd(c, "run", img)
66 61
 	// rebuild dockerfile with a small addition at the end
67
-	if _, err := buildImage(img, dockerfile2, true); err != nil {
68
-		c.Fatalf("Could not rebuild image %s: %v", img, err)
69
-	}
62
+	_, err = buildImage(img, dockerfile2, true)
63
+	c.Assert(err, check.IsNil, check.Commentf("Could not rebuild image %s", img))
70 64
 	// try to remove the image, should error out.
71
-	if out, _, err := dockerCmdWithError("rmi", img); err == nil {
72
-		c.Fatalf("Expected to error out removing the image, but succeeded: %s", out)
73
-	}
65
+	out, _, err := dockerCmdWithError("rmi", img)
66
+	c.Assert(err, check.NotNil, check.Commentf("Expected to error out removing the image, but succeeded: %s", out))
74 67
 
75 68
 	// check if we deleted the first image
76
-	out, _, err := dockerCmdWithError("images", "-q", "--no-trunc")
77
-	if err != nil {
78
-		c.Fatalf("%v: %s", err, out)
79
-	}
80
-	if !strings.Contains(out, img1) {
81
-		c.Fatalf("Orphaned container (could not find %q in docker images): %s", img1, out)
82
-	}
69
+	out, _ = dockerCmd(c, "images", "-q", "--no-trunc")
70
+	c.Assert(out, checker.Contains, img1, check.Commentf("Orphaned container (could not find %q in docker images): %s", img1, out))
71
+
83 72
 }
84 73
 
85 74
 func (s *DockerSuite) TestRmInvalidContainer(c *check.C) {