Browse code

Use checkers on Integration test when possible

Signed-off-by: Hu Keping <hukeping@huawei.com>

Hu Keping authored on 2015/10/09 04:42:41
Showing 2 changed files
... ...
@@ -3,6 +3,7 @@ package main
3 3
 import (
4 4
 	"strings"
5 5
 
6
+	"github.com/docker/docker/pkg/integration/checker"
6 7
 	"github.com/docker/docker/pkg/stringutils"
7 8
 	"github.com/go-check/check"
8 9
 )
... ...
@@ -27,14 +28,11 @@ func (s *DockerSuite) TestTagUnprefixedRepoByID(c *check.C) {
27 27
 
28 28
 // ensure we don't allow the use of invalid repository names; these tag operations should fail
29 29
 func (s *DockerSuite) TestTagInvalidUnprefixedRepo(c *check.C) {
30
-
31 30
 	invalidRepos := []string{"fo$z$", "Foo@3cc", "Foo$3", "Foo*3", "Fo^3", "Foo!3", "F)xcz(", "fo%asd"}
32 31
 
33 32
 	for _, repo := range invalidRepos {
34
-		_, _, err := dockerCmdWithError("tag", "busybox", repo)
35
-		if err == nil {
36
-			c.Fatalf("tag busybox %v should have failed", repo)
37
-		}
33
+		out, _, err := dockerCmdWithError("tag", "busybox", repo)
34
+		c.Assert(err, checker.NotNil, check.Commentf("tag busybox %v should have failed : %v", repo, out))
38 35
 	}
39 36
 }
40 37
 
... ...
@@ -45,10 +43,8 @@ func (s *DockerSuite) TestTagInvalidPrefixedRepo(c *check.C) {
45 45
 	invalidTags := []string{"repo:fo$z$", "repo:Foo@3cc", "repo:Foo$3", "repo:Foo*3", "repo:Fo^3", "repo:Foo!3", "repo:%goodbye", "repo:#hashtagit", "repo:F)xcz(", "repo:-foo", "repo:..", longTag}
46 46
 
47 47
 	for _, repotag := range invalidTags {
48
-		_, _, err := dockerCmdWithError("tag", "busybox", repotag)
49
-		if err == nil {
50
-			c.Fatalf("tag busybox %v should have failed", repotag)
51
-		}
48
+		out, _, err := dockerCmdWithError("tag", "busybox", repotag)
49
+		c.Assert(err, checker.NotNil, check.Commentf("tag busybox %v should have failed : %v", repotag, out))
52 50
 	}
53 51
 }
54 52
 
... ...
@@ -80,9 +76,9 @@ func (s *DockerSuite) TestTagExistedNameWithoutForce(c *check.C) {
80 80
 
81 81
 	dockerCmd(c, "tag", "busybox:latest", "busybox:test")
82 82
 	out, _, err := dockerCmdWithError("tag", "busybox:latest", "busybox:test")
83
-	if err == nil || !strings.Contains(out, "Conflict: Tag busybox:test is already set to image") {
84
-		c.Fatal("tag busybox busybox:test should have failed,because busybox:test is existed")
85
-	}
83
+
84
+	c.Assert(err, checker.NotNil, check.Commentf(out))
85
+	c.Assert(out, checker.Contains, "Conflict: Tag busybox:test is already set to image", check.Commentf("tag busybox busybox:test should have failed,because busybox:test is existed"))
86 86
 }
87 87
 
88 88
 // tag an image with an existed tag name with -f option should work
... ...
@@ -101,21 +97,21 @@ func (s *DockerSuite) TestTagWithPrefixHyphen(c *check.C) {
101 101
 	if err := pullImageIfNotExist("busybox:latest"); err != nil {
102 102
 		c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
103 103
 	}
104
+
104 105
 	// test repository name begin with '-'
105 106
 	out, _, err := dockerCmdWithError("tag", "busybox:latest", "-busybox:test")
106
-	if err == nil || !strings.Contains(out, "repository name component must match") {
107
-		c.Fatal("tag a name begin with '-' should failed")
108
-	}
107
+	c.Assert(err, checker.NotNil, check.Commentf(out))
108
+	c.Assert(out, checker.Contains, "repository name component must match", check.Commentf("tag a name begin with '-' should failed"))
109
+
109 110
 	// test namespace name begin with '-'
110 111
 	out, _, err = dockerCmdWithError("tag", "busybox:latest", "-test/busybox:test")
111
-	if err == nil || !strings.Contains(out, "repository name component must match") {
112
-		c.Fatal("tag a name begin with '-' should failed")
113
-	}
112
+	c.Assert(err, checker.NotNil, check.Commentf(out))
113
+	c.Assert(out, checker.Contains, "repository name component must match", check.Commentf("tag a name begin with '-' should failed"))
114
+
114 115
 	// test index name begin with '-'
115 116
 	out, _, err = dockerCmdWithError("tag", "busybox:latest", "-index:5000/busybox:test")
116
-	if err == nil || !strings.Contains(out, "Invalid index name (-index:5000). Cannot begin or end with a hyphen") {
117
-		c.Fatal("tag a name begin with '-' should failed")
118
-	}
117
+	c.Assert(err, checker.NotNil, check.Commentf(out))
118
+	c.Assert(out, checker.Contains, "Invalid index name (-index:5000). Cannot begin or end with a hyphen", check.Commentf("tag a name begin with '-' should failed"))
119 119
 }
120 120
 
121 121
 // ensure tagging using official names works
... ...
@@ -3,20 +3,17 @@ package main
3 3
 import (
4 4
 	"strings"
5 5
 
6
+	"github.com/docker/docker/pkg/integration/checker"
6 7
 	"github.com/go-check/check"
7 8
 )
8 9
 
9 10
 func (s *DockerSuite) TestTopMultipleArgs(c *check.C) {
10 11
 	testRequires(c, DaemonIsLinux)
11 12
 	out, _ := dockerCmd(c, "run", "-i", "-d", "busybox", "top")
12
-
13 13
 	cleanedContainerID := strings.TrimSpace(out)
14 14
 
15 15
 	out, _ = dockerCmd(c, "top", cleanedContainerID, "-o", "pid")
16
-	if !strings.Contains(out, "PID") {
17
-		c.Fatalf("did not see PID after top -o pid: %s", out)
18
-	}
19
-
16
+	c.Assert(out, checker.Contains, "PID", check.Commentf("did not see PID after top -o pid: %s", out))
20 17
 }
21 18
 
22 19
 func (s *DockerSuite) TestTopNonPrivileged(c *check.C) {
... ...
@@ -26,16 +23,10 @@ func (s *DockerSuite) TestTopNonPrivileged(c *check.C) {
26 26
 
27 27
 	out1, _ := dockerCmd(c, "top", cleanedContainerID)
28 28
 	out2, _ := dockerCmd(c, "top", cleanedContainerID)
29
-	out, _ = dockerCmd(c, "kill", cleanedContainerID)
30
-
31
-	if !strings.Contains(out1, "top") && !strings.Contains(out2, "top") {
32
-		c.Fatal("top should've listed `top` in the process list, but failed twice")
33
-	} else if !strings.Contains(out1, "top") {
34
-		c.Fatal("top should've listed `top` in the process list, but failed the first time")
35
-	} else if !strings.Contains(out2, "top") {
36
-		c.Fatal("top should've listed `top` in the process list, but failed the second itime")
37
-	}
29
+	dockerCmd(c, "kill", cleanedContainerID)
38 30
 
31
+	c.Assert(out1, checker.Contains, "top", check.Commentf("top should've listed `top` in the process list, but failed the first time"))
32
+	c.Assert(out2, checker.Contains, "top", check.Commentf("top should've listed `top` in the process list, but failed the second time"))
39 33
 }
40 34
 
41 35
 func (s *DockerSuite) TestTopPrivileged(c *check.C) {
... ...
@@ -45,14 +36,8 @@ func (s *DockerSuite) TestTopPrivileged(c *check.C) {
45 45
 
46 46
 	out1, _ := dockerCmd(c, "top", cleanedContainerID)
47 47
 	out2, _ := dockerCmd(c, "top", cleanedContainerID)
48
-	out, _ = dockerCmd(c, "kill", cleanedContainerID)
49
-
50
-	if !strings.Contains(out1, "top") && !strings.Contains(out2, "top") {
51
-		c.Fatal("top should've listed `top` in the process list, but failed twice")
52
-	} else if !strings.Contains(out1, "top") {
53
-		c.Fatal("top should've listed `top` in the process list, but failed the first time")
54
-	} else if !strings.Contains(out2, "top") {
55
-		c.Fatal("top should've listed `top` in the process list, but failed the second itime")
56
-	}
48
+	dockerCmd(c, "kill", cleanedContainerID)
57 49
 
50
+	c.Assert(out1, checker.Contains, "top", check.Commentf("top should've listed `top` in the process list, but failed the first time"))
51
+	c.Assert(out2, checker.Contains, "top", check.Commentf("top should've listed `top` in the process list, but failed the second time"))
58 52
 }