Browse code

Use checker on integration test when possible

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

Hu Keping authored on 2015/10/13 21:01:58
Showing 5 changed files
... ...
@@ -4,6 +4,7 @@ import (
4 4
 	"net/http"
5 5
 	"strings"
6 6
 
7
+	"github.com/docker/docker/pkg/integration/checker"
7 8
 	"github.com/go-check/check"
8 9
 )
9 10
 
... ...
@@ -42,7 +43,5 @@ func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) {
42 42
 	c.Assert(status, check.Equals, http.StatusInternalServerError)
43 43
 	c.Assert(err, check.IsNil)
44 44
 
45
-	if !strings.Contains(string(body), "Cannot resize container") && !strings.Contains(string(body), cleanedContainerID) {
46
-		c.Fatalf("resize should fail with message 'Cannot resize container' but instead received %s", string(body))
47
-	}
45
+	c.Assert(string(body), checker.Contains, "is not running", check.Commentf("resize should fail with message 'Container is not running'"))
48 46
 }
... ...
@@ -11,6 +11,7 @@ import (
11 11
 	"time"
12 12
 
13 13
 	"github.com/docker/docker/api/types"
14
+	"github.com/docker/docker/pkg/integration/checker"
14 15
 	"github.com/go-check/check"
15 16
 )
16 17
 
... ...
@@ -19,25 +20,24 @@ func (s *DockerSuite) TestApiStatsNoStreamGetCpu(c *check.C) {
19 19
 	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true;do echo 'Hello'; usleep 100000; done")
20 20
 
21 21
 	id := strings.TrimSpace(out)
22
-	c.Assert(waitRun(id), check.IsNil)
22
+	c.Assert(waitRun(id), checker.IsNil)
23 23
 
24 24
 	resp, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "")
25
-	c.Assert(err, check.IsNil)
26
-	c.Assert(resp.ContentLength > 0, check.Equals, true, check.Commentf("should not use chunked encoding"))
27
-	c.Assert(resp.Header.Get("Content-Type"), check.Equals, "application/json")
25
+	c.Assert(err, checker.IsNil)
26
+	c.Assert(resp.ContentLength, checker.GreaterThan, int64(0), check.Commentf("should not use chunked encoding"))
27
+	c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json")
28 28
 
29 29
 	var v *types.Stats
30 30
 	err = json.NewDecoder(body).Decode(&v)
31
-	c.Assert(err, check.IsNil)
31
+	c.Assert(err, checker.IsNil)
32 32
 	body.Close()
33 33
 
34 34
 	var cpuPercent = 0.0
35 35
 	cpuDelta := float64(v.CPUStats.CPUUsage.TotalUsage - v.PreCPUStats.CPUUsage.TotalUsage)
36 36
 	systemDelta := float64(v.CPUStats.SystemUsage - v.PreCPUStats.SystemUsage)
37 37
 	cpuPercent = (cpuDelta / systemDelta) * float64(len(v.CPUStats.CPUUsage.PercpuUsage)) * 100.0
38
-	if cpuPercent == 0 {
39
-		c.Fatalf("docker stats with no-stream get cpu usage failed: was %v", cpuPercent)
40
-	}
38
+
39
+	c.Assert(cpuPercent, check.Not(checker.Equals), 0.0, check.Commentf("docker stats with no-stream get cpu usage failed: was %v", cpuPercent))
41 40
 }
42 41
 
43 42
 func (s *DockerSuite) TestApiStatsStoppedContainerInGoroutines(c *check.C) {
... ...
@@ -47,10 +47,10 @@ func (s *DockerSuite) TestApiStatsStoppedContainerInGoroutines(c *check.C) {
47 47
 
48 48
 	getGoRoutines := func() int {
49 49
 		_, body, err := sockRequestRaw("GET", fmt.Sprintf("/info"), nil, "")
50
-		c.Assert(err, check.IsNil)
50
+		c.Assert(err, checker.IsNil)
51 51
 		info := types.Info{}
52 52
 		err = json.NewDecoder(body).Decode(&info)
53
-		c.Assert(err, check.IsNil)
53
+		c.Assert(err, checker.IsNil)
54 54
 		body.Close()
55 55
 		return info.NGoroutines
56 56
 	}
... ...
@@ -58,14 +58,14 @@ func (s *DockerSuite) TestApiStatsStoppedContainerInGoroutines(c *check.C) {
58 58
 	// When the HTTP connection is closed, the number of goroutines should not increase.
59 59
 	routines := getGoRoutines()
60 60
 	_, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats", id), nil, "")
61
-	c.Assert(err, check.IsNil)
61
+	c.Assert(err, checker.IsNil)
62 62
 	body.Close()
63 63
 
64 64
 	t := time.After(30 * time.Second)
65 65
 	for {
66 66
 		select {
67 67
 		case <-t:
68
-			c.Assert(getGoRoutines() <= routines, check.Equals, true)
68
+			c.Assert(getGoRoutines(), checker.LessOrEqualThan, routines)
69 69
 			return
70 70
 		default:
71 71
 			if n := getGoRoutines(); n <= routines {
... ...
@@ -82,7 +82,7 @@ func (s *DockerSuite) TestApiStatsNetworkStats(c *check.C) {
82 82
 	// Run container for 30 secs
83 83
 	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
84 84
 	id := strings.TrimSpace(out)
85
-	c.Assert(waitRun(id), check.IsNil)
85
+	c.Assert(waitRun(id), checker.IsNil)
86 86
 
87 87
 	// Retrieve the container address
88 88
 	contIP := findContainerIP(c, id)
... ...
@@ -106,7 +106,7 @@ func (s *DockerSuite) TestApiStatsNetworkStats(c *check.C) {
106 106
 	}
107 107
 	pingout, err := exec.Command("ping", contIP, countParam, strconv.Itoa(numPings)).Output()
108 108
 	pingouts := string(pingout[:])
109
-	c.Assert(err, check.IsNil)
109
+	c.Assert(err, checker.IsNil)
110 110
 	nwStatsPost := getNetworkStats(c, id)
111 111
 	for _, v := range nwStatsPost {
112 112
 		postRxPackets += v.RxPackets
... ...
@@ -116,9 +116,9 @@ func (s *DockerSuite) TestApiStatsNetworkStats(c *check.C) {
116 116
 	// Verify the stats contain at least the expected number of packets (account for ARP)
117 117
 	expRxPkts := 1 + preRxPackets + uint64(numPings)
118 118
 	expTxPkts := 1 + preTxPackets + uint64(numPings)
119
-	c.Assert(postTxPackets >= expTxPkts, check.Equals, true,
119
+	c.Assert(postTxPackets, checker.GreaterOrEqualThan, expTxPkts,
120 120
 		check.Commentf("Reported less TxPackets than expected. Expected >= %d. Found %d. %s", expTxPkts, postTxPackets, pingouts))
121
-	c.Assert(postRxPackets >= expRxPkts, check.Equals, true,
121
+	c.Assert(postRxPackets, checker.GreaterOrEqualThan, expRxPkts,
122 122
 		check.Commentf("Reported less Txbytes than expected. Expected >= %d. Found %d. %s", expRxPkts, postRxPackets, pingouts))
123 123
 }
124 124
 
... ...
@@ -126,10 +126,10 @@ func getNetworkStats(c *check.C, id string) map[string]types.NetworkStats {
126 126
 	var st *types.StatsJSON
127 127
 
128 128
 	_, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "")
129
-	c.Assert(err, check.IsNil)
129
+	c.Assert(err, checker.IsNil)
130 130
 
131 131
 	err = json.NewDecoder(body).Decode(&st)
132
-	c.Assert(err, check.IsNil)
132
+	c.Assert(err, checker.IsNil)
133 133
 	body.Close()
134 134
 
135 135
 	return st.Networks
... ...
@@ -139,10 +139,10 @@ func (s *DockerSuite) TestApiStatsContainerNotFound(c *check.C) {
139 139
 	testRequires(c, DaemonIsLinux)
140 140
 
141 141
 	status, _, err := sockRequest("GET", "/containers/nonexistent/stats", nil)
142
-	c.Assert(err, check.IsNil)
143
-	c.Assert(status, check.Equals, http.StatusNotFound)
142
+	c.Assert(err, checker.IsNil)
143
+	c.Assert(status, checker.Equals, http.StatusNotFound)
144 144
 
145 145
 	status, _, err = sockRequest("GET", "/containers/nonexistent/stats?stream=0", nil)
146
-	c.Assert(err, check.IsNil)
147
-	c.Assert(status, check.Equals, http.StatusNotFound)
146
+	c.Assert(err, checker.IsNil)
147
+	c.Assert(status, checker.Equals, http.StatusNotFound)
148 148
 }
... ...
@@ -8,19 +8,20 @@ import (
8 8
 	"time"
9 9
 
10 10
 	"github.com/docker/docker/api"
11
+	"github.com/docker/docker/pkg/integration/checker"
11 12
 	"github.com/go-check/check"
12 13
 )
13 14
 
14 15
 func (s *DockerSuite) TestApiOptionsRoute(c *check.C) {
15 16
 	status, _, err := sockRequest("OPTIONS", "/", nil)
16
-	c.Assert(err, check.IsNil)
17
-	c.Assert(status, check.Equals, http.StatusOK)
17
+	c.Assert(err, checker.IsNil)
18
+	c.Assert(status, checker.Equals, http.StatusOK)
18 19
 }
19 20
 
20 21
 func (s *DockerSuite) TestApiGetEnabledCors(c *check.C) {
21 22
 	res, body, err := sockRequestRaw("GET", "/version", nil, "")
22
-	c.Assert(err, check.IsNil)
23
-	c.Assert(res.StatusCode, check.Equals, http.StatusOK)
23
+	c.Assert(err, checker.IsNil)
24
+	c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
24 25
 	body.Close()
25 26
 	// TODO: @runcom incomplete tests, why old integration tests had this headers
26 27
 	// and here none of the headers below are in the response?
... ...
@@ -31,43 +32,43 @@ func (s *DockerSuite) TestApiGetEnabledCors(c *check.C) {
31 31
 
32 32
 func (s *DockerSuite) TestApiVersionStatusCode(c *check.C) {
33 33
 	conn, err := sockConn(time.Duration(10 * time.Second))
34
-	c.Assert(err, check.IsNil)
34
+	c.Assert(err, checker.IsNil)
35 35
 
36 36
 	client := httputil.NewClientConn(conn, nil)
37 37
 	defer client.Close()
38 38
 
39 39
 	req, err := http.NewRequest("GET", "/v999.0/version", nil)
40
-	c.Assert(err, check.IsNil)
40
+	c.Assert(err, checker.IsNil)
41 41
 	req.Header.Set("User-Agent", "Docker-Client/999.0 (os)")
42 42
 
43 43
 	res, err := client.Do(req)
44
-	c.Assert(res.StatusCode, check.Equals, http.StatusBadRequest)
44
+	c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
45 45
 }
46 46
 
47 47
 func (s *DockerSuite) TestApiClientVersionNewerThanServer(c *check.C) {
48 48
 	v := strings.Split(string(api.Version), ".")
49 49
 	vMinInt, err := strconv.Atoi(v[1])
50
-	c.Assert(err, check.IsNil)
50
+	c.Assert(err, checker.IsNil)
51 51
 	vMinInt++
52 52
 	v[1] = strconv.Itoa(vMinInt)
53 53
 	version := strings.Join(v, ".")
54 54
 
55 55
 	status, body, err := sockRequest("GET", "/v"+version+"/version", nil)
56
-	c.Assert(err, check.IsNil)
57
-	c.Assert(status, check.Equals, http.StatusBadRequest)
58
-	c.Assert(len(string(body)), check.Not(check.Equals), 0) // Expected not empty body
56
+	c.Assert(err, checker.IsNil)
57
+	c.Assert(status, checker.Equals, http.StatusBadRequest)
58
+	c.Assert(len(string(body)), check.Not(checker.Equals), 0) // Expected not empty body
59 59
 }
60 60
 
61 61
 func (s *DockerSuite) TestApiClientVersionOldNotSupported(c *check.C) {
62 62
 	v := strings.Split(string(api.MinVersion), ".")
63 63
 	vMinInt, err := strconv.Atoi(v[1])
64
-	c.Assert(err, check.IsNil)
64
+	c.Assert(err, checker.IsNil)
65 65
 	vMinInt--
66 66
 	v[1] = strconv.Itoa(vMinInt)
67 67
 	version := strings.Join(v, ".")
68 68
 
69 69
 	status, body, err := sockRequest("GET", "/v"+version+"/version", nil)
70
-	c.Assert(err, check.IsNil)
71
-	c.Assert(status, check.Equals, http.StatusBadRequest)
72
-	c.Assert(len(string(body)), check.Not(check.Equals), 0) // Expected not empty body
70
+	c.Assert(err, checker.IsNil)
71
+	c.Assert(status, checker.Equals, http.StatusBadRequest)
72
+	c.Assert(len(string(body)), checker.Not(check.Equals), 0) // Expected not empty body
73 73
 }
... ...
@@ -6,6 +6,7 @@ import (
6 6
 	"path"
7 7
 
8 8
 	"github.com/docker/docker/api/types"
9
+	"github.com/docker/docker/pkg/integration/checker"
9 10
 	"github.com/go-check/check"
10 11
 )
11 12
 
... ...
@@ -14,13 +15,13 @@ func (s *DockerSuite) TestVolumesApiList(c *check.C) {
14 14
 	dockerCmd(c, "run", "-d", "-v", "/foo", "busybox")
15 15
 
16 16
 	status, b, err := sockRequest("GET", "/volumes", nil)
17
-	c.Assert(err, check.IsNil)
18
-	c.Assert(status, check.Equals, http.StatusOK)
17
+	c.Assert(err, checker.IsNil)
18
+	c.Assert(status, checker.Equals, http.StatusOK)
19 19
 
20 20
 	var volumes types.VolumesListResponse
21
-	c.Assert(json.Unmarshal(b, &volumes), check.IsNil)
21
+	c.Assert(json.Unmarshal(b, &volumes), checker.IsNil)
22 22
 
23
-	c.Assert(len(volumes.Volumes), check.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
23
+	c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
24 24
 }
25 25
 
26 26
 func (s *DockerSuite) TestVolumesApiCreate(c *check.C) {
... ...
@@ -34,9 +35,9 @@ func (s *DockerSuite) TestVolumesApiCreate(c *check.C) {
34 34
 
35 35
 	var vol types.Volume
36 36
 	err = json.Unmarshal(b, &vol)
37
-	c.Assert(err, check.IsNil)
37
+	c.Assert(err, checker.IsNil)
38 38
 
39
-	c.Assert(path.Base(path.Dir(vol.Mountpoint)), check.Equals, config.Name)
39
+	c.Assert(path.Base(path.Dir(vol.Mountpoint)), checker.Equals, config.Name)
40 40
 }
41 41
 
42 42
 func (s *DockerSuite) TestVolumesApiRemove(c *check.C) {
... ...
@@ -44,22 +45,22 @@ func (s *DockerSuite) TestVolumesApiRemove(c *check.C) {
44 44
 	dockerCmd(c, "run", "-d", "-v", "/foo", "--name=test", "busybox")
45 45
 
46 46
 	status, b, err := sockRequest("GET", "/volumes", nil)
47
-	c.Assert(err, check.IsNil)
48
-	c.Assert(status, check.Equals, http.StatusOK)
47
+	c.Assert(err, checker.IsNil)
48
+	c.Assert(status, checker.Equals, http.StatusOK)
49 49
 
50 50
 	var volumes types.VolumesListResponse
51
-	c.Assert(json.Unmarshal(b, &volumes), check.IsNil)
52
-	c.Assert(len(volumes.Volumes), check.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
51
+	c.Assert(json.Unmarshal(b, &volumes), checker.IsNil)
52
+	c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
53 53
 
54 54
 	v := volumes.Volumes[0]
55 55
 	status, _, err = sockRequest("DELETE", "/volumes/"+v.Name, nil)
56
-	c.Assert(err, check.IsNil)
57
-	c.Assert(status, check.Equals, http.StatusConflict, check.Commentf("Should not be able to remove a volume that is in use"))
56
+	c.Assert(err, checker.IsNil)
57
+	c.Assert(status, checker.Equals, http.StatusConflict, check.Commentf("Should not be able to remove a volume that is in use"))
58 58
 
59 59
 	dockerCmd(c, "rm", "-f", "test")
60 60
 	status, data, err := sockRequest("DELETE", "/volumes/"+v.Name, nil)
61
-	c.Assert(err, check.IsNil)
62
-	c.Assert(status, check.Equals, http.StatusNoContent, check.Commentf(string(data)))
61
+	c.Assert(err, checker.IsNil)
62
+	c.Assert(status, checker.Equals, http.StatusNoContent, check.Commentf(string(data)))
63 63
 
64 64
 }
65 65
 
... ...
@@ -73,17 +74,17 @@ func (s *DockerSuite) TestVolumesApiInspect(c *check.C) {
73 73
 	c.Assert(status, check.Equals, http.StatusCreated, check.Commentf(string(b)))
74 74
 
75 75
 	status, b, err = sockRequest("GET", "/volumes", nil)
76
-	c.Assert(err, check.IsNil)
77
-	c.Assert(status, check.Equals, http.StatusOK, check.Commentf(string(b)))
76
+	c.Assert(err, checker.IsNil)
77
+	c.Assert(status, checker.Equals, http.StatusOK, check.Commentf(string(b)))
78 78
 
79 79
 	var volumes types.VolumesListResponse
80
-	c.Assert(json.Unmarshal(b, &volumes), check.IsNil)
81
-	c.Assert(len(volumes.Volumes), check.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
80
+	c.Assert(json.Unmarshal(b, &volumes), checker.IsNil)
81
+	c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
82 82
 
83 83
 	var vol types.Volume
84 84
 	status, b, err = sockRequest("GET", "/volumes/"+config.Name, nil)
85
-	c.Assert(err, check.IsNil)
86
-	c.Assert(status, check.Equals, http.StatusOK, check.Commentf(string(b)))
87
-	c.Assert(json.Unmarshal(b, &vol), check.IsNil)
88
-	c.Assert(vol.Name, check.Equals, config.Name)
85
+	c.Assert(err, checker.IsNil)
86
+	c.Assert(status, checker.Equals, http.StatusOK, check.Commentf(string(b)))
87
+	c.Assert(json.Unmarshal(b, &vol), checker.IsNil)
88
+	c.Assert(vol.Name, checker.Equals, config.Name)
89 89
 }
... ...
@@ -9,6 +9,7 @@ import (
9 9
 	"strings"
10 10
 	"time"
11 11
 
12
+	"github.com/docker/docker/pkg/integration/checker"
12 13
 	"github.com/go-check/check"
13 14
 )
14 15
 
... ...
@@ -23,32 +24,26 @@ func (s *DockerRegistrySuite) TestPushBusyboxImage(c *check.C) {
23 23
 
24 24
 // pushing an image without a prefix should throw an error
25 25
 func (s *DockerSuite) TestPushUnprefixedRepo(c *check.C) {
26
-	if out, _, err := dockerCmdWithError("push", "busybox"); err == nil {
27
-		c.Fatalf("pushing an unprefixed repo didn't result in a non-zero exit status: %s", out)
28
-	}
26
+	out, _, err := dockerCmdWithError("push", "busybox")
27
+	c.Assert(err, check.NotNil, check.Commentf("pushing an unprefixed repo didn't result in a non-zero exit status: %s", out))
29 28
 }
30 29
 
31 30
 func (s *DockerRegistrySuite) TestPushUntagged(c *check.C) {
32 31
 	repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
33
-
34 32
 	expected := "Repository does not exist"
35
-	if out, _, err := dockerCmdWithError("push", repoName); err == nil {
36
-		c.Fatalf("pushing the image to the private registry should have failed: output %q", out)
37
-	} else if !strings.Contains(out, expected) {
38
-		c.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out)
39
-	}
33
+
34
+	out, _, err := dockerCmdWithError("push", repoName)
35
+	c.Assert(err, check.NotNil, check.Commentf("pushing the image to the private registry should have failed: output %q", out))
36
+	c.Assert(out, checker.Contains, expected, check.Commentf("pushing the image failed"))
40 37
 }
41 38
 
42 39
 func (s *DockerRegistrySuite) TestPushBadTag(c *check.C) {
43 40
 	repoName := fmt.Sprintf("%v/dockercli/busybox:latest", privateRegistryURL)
44
-
45 41
 	expected := "does not exist"
46 42
 
47
-	if out, _, err := dockerCmdWithError("push", repoName); err == nil {
48
-		c.Fatalf("pushing the image to the private registry should have failed: output %q", out)
49
-	} else if !strings.Contains(out, expected) {
50
-		c.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out)
51
-	}
43
+	out, _, err := dockerCmdWithError("push", repoName)
44
+	c.Assert(err, check.NotNil, check.Commentf("pushing the image to the private registry should have failed: output %q", out))
45
+	c.Assert(out, checker.Contains, expected, check.Commentf("pushing the image failed"))
52 46
 }
53 47
 
54 48
 func (s *DockerRegistrySuite) TestPushMultipleTags(c *check.C) {
... ...
@@ -64,9 +59,7 @@ func (s *DockerRegistrySuite) TestPushMultipleTags(c *check.C) {
64 64
 
65 65
 	// Ensure layer list is equivalent for repoTag1 and repoTag2
66 66
 	out1, _ := dockerCmd(c, "pull", repoTag1)
67
-	if strings.Contains(out1, "Tag t1 not found") {
68
-		c.Fatalf("Unable to pull pushed image: %s", out1)
69
-	}
67
+
70 68
 	imageAlreadyExists := ": Image already exists"
71 69
 	var out1Lines []string
72 70
 	for _, outputLine := range strings.Split(out1, "\n") {
... ...
@@ -76,54 +69,40 @@ func (s *DockerRegistrySuite) TestPushMultipleTags(c *check.C) {
76 76
 	}
77 77
 
78 78
 	out2, _ := dockerCmd(c, "pull", repoTag2)
79
-	if strings.Contains(out2, "Tag t2 not found") {
80
-		c.Fatalf("Unable to pull pushed image: %s", out1)
81
-	}
79
+
82 80
 	var out2Lines []string
83 81
 	for _, outputLine := range strings.Split(out2, "\n") {
84 82
 		if strings.Contains(outputLine, imageAlreadyExists) {
85 83
 			out1Lines = append(out1Lines, outputLine)
86 84
 		}
87 85
 	}
88
-
89
-	if len(out1Lines) != len(out2Lines) {
90
-		c.Fatalf("Mismatched output length:\n%s\n%s", out1, out2)
91
-	}
86
+	c.Assert(out2Lines, checker.HasLen, len(out1Lines))
92 87
 
93 88
 	for i := range out1Lines {
94
-		if out1Lines[i] != out2Lines[i] {
95
-			c.Fatalf("Mismatched output line:\n%s\n%s", out1Lines[i], out2Lines[i])
96
-		}
89
+		c.Assert(out1Lines[i], checker.Equals, out2Lines[i])
97 90
 	}
98 91
 }
99 92
 
100 93
 func (s *DockerRegistrySuite) TestPushEmptyLayer(c *check.C) {
101 94
 	repoName := fmt.Sprintf("%v/dockercli/emptylayer", privateRegistryURL)
102 95
 	emptyTarball, err := ioutil.TempFile("", "empty_tarball")
103
-	if err != nil {
104
-		c.Fatalf("Unable to create test file: %v", err)
105
-	}
96
+	c.Assert(err, check.IsNil, check.Commentf("Unable to create test file"))
97
+
106 98
 	tw := tar.NewWriter(emptyTarball)
107 99
 	err = tw.Close()
108
-	if err != nil {
109
-		c.Fatalf("Error creating empty tarball: %v", err)
110
-	}
100
+	c.Assert(err, check.IsNil, check.Commentf("Error creating empty tarball"))
101
+
111 102
 	freader, err := os.Open(emptyTarball.Name())
112
-	if err != nil {
113
-		c.Fatalf("Could not open test tarball: %v", err)
114
-	}
103
+	c.Assert(err, check.IsNil, check.Commentf("Could not open test tarball"))
115 104
 
116 105
 	importCmd := exec.Command(dockerBinary, "import", "-", repoName)
117 106
 	importCmd.Stdin = freader
118 107
 	out, _, err := runCommandWithOutput(importCmd)
119
-	if err != nil {
120
-		c.Errorf("import failed with errors: %v, output: %q", err, out)
121
-	}
108
+	c.Assert(err, check.IsNil, check.Commentf("import failed: %q", out))
122 109
 
123 110
 	// Now verify we can push it
124
-	if out, _, err := dockerCmdWithError("push", repoName); err != nil {
125
-		c.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err)
126
-	}
111
+	out, _, err = dockerCmdWithError("push", repoName)
112
+	c.Assert(err, check.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out))
127 113
 }
128 114
 
129 115
 func (s *DockerTrustSuite) TestTrustedPush(c *check.C) {
... ...
@@ -134,12 +113,8 @@ func (s *DockerTrustSuite) TestTrustedPush(c *check.C) {
134 134
 	pushCmd := exec.Command(dockerBinary, "push", repoName)
135 135
 	s.trustedCmd(pushCmd)
136 136
 	out, _, err := runCommandWithOutput(pushCmd)
137
-	if err != nil {
138
-		c.Fatalf("Error running trusted push: %s\n%s", err, out)
139
-	}
140
-	if !strings.Contains(string(out), "Signing and pushing trust metadata") {
141
-		c.Fatalf("Missing expected output on trusted push:\n%s", out)
142
-	}
137
+	c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out))
138
+	c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
143 139
 }
144 140
 
145 141
 func (s *DockerTrustSuite) TestTrustedPushWithEnvPasswords(c *check.C) {
... ...
@@ -150,12 +125,8 @@ func (s *DockerTrustSuite) TestTrustedPushWithEnvPasswords(c *check.C) {
150 150
 	pushCmd := exec.Command(dockerBinary, "push", repoName)
151 151
 	s.trustedCmdWithPassphrases(pushCmd, "12345678", "12345678")
152 152
 	out, _, err := runCommandWithOutput(pushCmd)
153
-	if err != nil {
154
-		c.Fatalf("Error running trusted push: %s\n%s", err, out)
155
-	}
156
-	if !strings.Contains(string(out), "Signing and pushing trust metadata") {
157
-		c.Fatalf("Missing expected output on trusted push:\n%s", out)
158
-	}
153
+	c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out))
154
+	c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
159 155
 }
160 156
 
161 157
 // This test ensures backwards compatibility with old ENV variables. Should be
... ...
@@ -168,12 +139,8 @@ func (s *DockerTrustSuite) TestTrustedPushWithDeprecatedEnvPasswords(c *check.C)
168 168
 	pushCmd := exec.Command(dockerBinary, "push", repoName)
169 169
 	s.trustedCmdWithDeprecatedEnvPassphrases(pushCmd, "12345678", "12345678")
170 170
 	out, _, err := runCommandWithOutput(pushCmd)
171
-	if err != nil {
172
-		c.Fatalf("Error running trusted push: %s\n%s", err, out)
173
-	}
174
-	if !strings.Contains(string(out), "Signing and pushing trust metadata") {
175
-		c.Fatalf("Missing expected output on trusted push:\n%s", out)
176
-	}
171
+	c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out))
172
+	c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
177 173
 }
178 174
 
179 175
 func (s *DockerTrustSuite) TestTrustedPushWithFaillingServer(c *check.C) {
... ...
@@ -184,13 +151,8 @@ func (s *DockerTrustSuite) TestTrustedPushWithFaillingServer(c *check.C) {
184 184
 	pushCmd := exec.Command(dockerBinary, "push", repoName)
185 185
 	s.trustedCmdWithServer(pushCmd, "https://example.com:81/")
186 186
 	out, _, err := runCommandWithOutput(pushCmd)
187
-	if err == nil {
188
-		c.Fatalf("Missing error while running trusted push w/ no server")
189
-	}
190
-
191
-	if !strings.Contains(string(out), "error contacting notary server") {
192
-		c.Fatalf("Missing expected output on trusted push:\n%s", out)
193
-	}
187
+	c.Assert(err, check.NotNil, check.Commentf("Missing error while running trusted push w/ no server"))
188
+	c.Assert(out, checker.Contains, "error contacting notary server", check.Commentf("Missing expected output on trusted push"))
194 189
 }
195 190
 
196 191
 func (s *DockerTrustSuite) TestTrustedPushWithoutServerAndUntrusted(c *check.C) {
... ...
@@ -201,13 +163,8 @@ func (s *DockerTrustSuite) TestTrustedPushWithoutServerAndUntrusted(c *check.C)
201 201
 	pushCmd := exec.Command(dockerBinary, "push", "--disable-content-trust", repoName)
202 202
 	s.trustedCmdWithServer(pushCmd, "https://example.com/")
203 203
 	out, _, err := runCommandWithOutput(pushCmd)
204
-	if err != nil {
205
-		c.Fatalf("trusted push with no server and --disable-content-trust failed: %s\n%s", err, out)
206
-	}
207
-
208
-	if strings.Contains(string(out), "Error establishing connection to notary repository") {
209
-		c.Fatalf("Missing expected output on trusted push with --disable-content-trust:\n%s", out)
210
-	}
204
+	c.Assert(err, check.IsNil, check.Commentf("trusted push with no server and --disable-content-trust failed: %s\n%s", err, out))
205
+	c.Assert(out, check.Not(checker.Contains), "Error establishing connection to notary repository", check.Commentf("Missing expected output on trusted push with --disable-content-trust:"))
211 206
 }
212 207
 
213 208
 func (s *DockerTrustSuite) TestTrustedPushWithExistingTag(c *check.C) {
... ...
@@ -219,13 +176,8 @@ func (s *DockerTrustSuite) TestTrustedPushWithExistingTag(c *check.C) {
219 219
 	pushCmd := exec.Command(dockerBinary, "push", repoName)
220 220
 	s.trustedCmd(pushCmd)
221 221
 	out, _, err := runCommandWithOutput(pushCmd)
222
-	if err != nil {
223
-		c.Fatalf("trusted push failed: %s\n%s", err, out)
224
-	}
225
-
226
-	if !strings.Contains(string(out), "Signing and pushing trust metadata") {
227
-		c.Fatalf("Missing expected output on trusted push with existing tag:\n%s", out)
228
-	}
222
+	c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
223
+	c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag"))
229 224
 }
230 225
 
231 226
 func (s *DockerTrustSuite) TestTrustedPushWithExistingSignedTag(c *check.C) {
... ...
@@ -237,25 +189,15 @@ func (s *DockerTrustSuite) TestTrustedPushWithExistingSignedTag(c *check.C) {
237 237
 	pushCmd := exec.Command(dockerBinary, "push", repoName)
238 238
 	s.trustedCmd(pushCmd)
239 239
 	out, _, err := runCommandWithOutput(pushCmd)
240
-	if err != nil {
241
-		c.Fatalf("trusted push failed: %s\n%s", err, out)
242
-	}
243
-
244
-	if !strings.Contains(string(out), "Signing and pushing trust metadata") {
245
-		c.Fatalf("Missing expected output on trusted push with existing tag:\n%s", out)
246
-	}
240
+	c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
241
+	c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag"))
247 242
 
248 243
 	// Do another trusted push
249 244
 	pushCmd = exec.Command(dockerBinary, "push", repoName)
250 245
 	s.trustedCmd(pushCmd)
251 246
 	out, _, err = runCommandWithOutput(pushCmd)
252
-	if err != nil {
253
-		c.Fatalf("trusted push failed: %s\n%s", err, out)
254
-	}
255
-
256
-	if !strings.Contains(string(out), "Signing and pushing trust metadata") {
257
-		c.Fatalf("Missing expected output on trusted push with existing tag:\n%s", out)
258
-	}
247
+	c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
248
+	c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag"))
259 249
 
260 250
 	dockerCmd(c, "rmi", repoName)
261 251
 
... ...
@@ -263,13 +205,9 @@ func (s *DockerTrustSuite) TestTrustedPushWithExistingSignedTag(c *check.C) {
263 263
 	pullCmd := exec.Command(dockerBinary, "pull", repoName)
264 264
 	s.trustedCmd(pullCmd)
265 265
 	out, _, err = runCommandWithOutput(pullCmd)
266
-	if err != nil {
267
-		c.Fatalf("Error running trusted pull: %s\n%s", err, out)
268
-	}
266
+	c.Assert(err, check.IsNil, check.Commentf("Error running trusted pull: %s\n%s", err, out))
267
+	c.Assert(out, checker.Contains, "Status: Downloaded", check.Commentf("Missing expected output on trusted pull with --disable-content-trust"))
269 268
 
270
-	if !strings.Contains(string(out), "Status: Downloaded") {
271
-		c.Fatalf("Missing expected output on trusted pull with --disable-content-trust:\n%s", out)
272
-	}
273 269
 }
274 270
 
275 271
 func (s *DockerTrustSuite) TestTrustedPushWithIncorrectPassphraseForNonRoot(c *check.C) {
... ...
@@ -281,25 +219,15 @@ func (s *DockerTrustSuite) TestTrustedPushWithIncorrectPassphraseForNonRoot(c *c
281 281
 	pushCmd := exec.Command(dockerBinary, "push", repoName)
282 282
 	s.trustedCmd(pushCmd)
283 283
 	out, _, err := runCommandWithOutput(pushCmd)
284
-	if err != nil {
285
-		c.Fatalf("trusted push failed: %s\n%s", err, out)
286
-	}
287
-
288
-	if !strings.Contains(string(out), "Signing and pushing trust metadata") {
289
-		c.Fatalf("Missing expected output on trusted push:\n%s", out)
290
-	}
284
+	c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
285
+	c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push:\n%s", out))
291 286
 
292 287
 	// Push with wrong passphrases
293 288
 	pushCmd = exec.Command(dockerBinary, "push", repoName)
294 289
 	s.trustedCmdWithPassphrases(pushCmd, "12345678", "87654321")
295 290
 	out, _, err = runCommandWithOutput(pushCmd)
296
-	if err == nil {
297
-		c.Fatalf("Error missing from trusted push with short targets passphrase: \n%s", out)
298
-	}
299
-
300
-	if !strings.Contains(string(out), "password invalid, operation has failed") {
301
-		c.Fatalf("Missing expected output on trusted push with short targets/snapsnot passphrase:\n%s", out)
302
-	}
291
+	c.Assert(err, check.NotNil, check.Commentf("Error missing from trusted push with short targets passphrase: \n%s", out))
292
+	c.Assert(out, checker.Contains, "password invalid, operation has failed", check.Commentf("Missing expected output on trusted push with short targets/snapsnot passphrase"))
303 293
 }
304 294
 
305 295
 // This test ensures backwards compatibility with old ENV variables. Should be
... ...
@@ -313,25 +241,15 @@ func (s *DockerTrustSuite) TestTrustedPushWithIncorrectDeprecatedPassphraseForNo
313 313
 	pushCmd := exec.Command(dockerBinary, "push", repoName)
314 314
 	s.trustedCmd(pushCmd)
315 315
 	out, _, err := runCommandWithOutput(pushCmd)
316
-	if err != nil {
317
-		c.Fatalf("trusted push failed: %s\n%s", err, out)
318
-	}
319
-
320
-	if !strings.Contains(string(out), "Signing and pushing trust metadata") {
321
-		c.Fatalf("Missing expected output on trusted push:\n%s", out)
322
-	}
316
+	c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
317
+	c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
323 318
 
324 319
 	// Push with wrong passphrases
325 320
 	pushCmd = exec.Command(dockerBinary, "push", repoName)
326 321
 	s.trustedCmdWithDeprecatedEnvPassphrases(pushCmd, "12345678", "87654321")
327 322
 	out, _, err = runCommandWithOutput(pushCmd)
328
-	if err == nil {
329
-		c.Fatalf("Error missing from trusted push with short targets passphrase: \n%s", out)
330
-	}
331
-
332
-	if !strings.Contains(string(out), "password invalid, operation has failed") {
333
-		c.Fatalf("Missing expected output on trusted push with short targets/snapsnot passphrase:\n%s", out)
334
-	}
323
+	c.Assert(err, check.NotNil, check.Commentf("Error missing from trusted push with short targets passphrase: \n%s", out))
324
+	c.Assert(out, checker.Contains, "password invalid, operation has failed", check.Commentf("Missing expected output on trusted push with short targets/snapsnot passphrase"))
335 325
 }
336 326
 
337 327
 func (s *DockerTrustSuite) TestTrustedPushWithExpiredSnapshot(c *check.C) {
... ...
@@ -344,13 +262,8 @@ func (s *DockerTrustSuite) TestTrustedPushWithExpiredSnapshot(c *check.C) {
344 344
 	pushCmd := exec.Command(dockerBinary, "push", repoName)
345 345
 	s.trustedCmd(pushCmd)
346 346
 	out, _, err := runCommandWithOutput(pushCmd)
347
-	if err != nil {
348
-		c.Fatalf("trusted push failed: %s\n%s", err, out)
349
-	}
350
-
351
-	if !strings.Contains(string(out), "Signing and pushing trust metadata") {
352
-		c.Fatalf("Missing expected output on trusted push:\n%s", out)
353
-	}
347
+	c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
348
+	c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
354 349
 
355 350
 	// Snapshots last for three years. This should be expired
356 351
 	fourYearsLater := time.Now().Add(time.Hour * 24 * 365 * 4)
... ...
@@ -360,13 +273,8 @@ func (s *DockerTrustSuite) TestTrustedPushWithExpiredSnapshot(c *check.C) {
360 360
 		pushCmd = exec.Command(dockerBinary, "push", repoName)
361 361
 		s.trustedCmd(pushCmd)
362 362
 		out, _, err = runCommandWithOutput(pushCmd)
363
-		if err == nil {
364
-			c.Fatalf("Error missing from trusted push with expired snapshot: \n%s", out)
365
-		}
366
-
367
-		if !strings.Contains(string(out), "repository out-of-date") {
368
-			c.Fatalf("Missing expected output on trusted push with expired snapshot:\n%s", out)
369
-		}
363
+		c.Assert(err, check.NotNil, check.Commentf("Error missing from trusted push with expired snapshot: \n%s", out))
364
+		c.Assert(out, checker.Contains, "repository out-of-date", check.Commentf("Missing expected output on trusted push with expired snapshot"))
370 365
 	})
371 366
 }
372 367
 
... ...
@@ -380,13 +288,8 @@ func (s *DockerTrustSuite) TestTrustedPushWithExpiredTimestamp(c *check.C) {
380 380
 	pushCmd := exec.Command(dockerBinary, "push", repoName)
381 381
 	s.trustedCmd(pushCmd)
382 382
 	out, _, err := runCommandWithOutput(pushCmd)
383
-	if err != nil {
384
-		c.Fatalf("trusted push failed: %s\n%s", err, out)
385
-	}
386
-
387
-	if !strings.Contains(string(out), "Signing and pushing trust metadata") {
388
-		c.Fatalf("Missing expected output on trusted push:\n%s", out)
389
-	}
383
+	c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
384
+	c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
390 385
 
391 386
 	// The timestamps expire in two weeks. Lets check three
392 387
 	threeWeeksLater := time.Now().Add(time.Hour * 24 * 21)
... ...
@@ -396,11 +299,7 @@ func (s *DockerTrustSuite) TestTrustedPushWithExpiredTimestamp(c *check.C) {
396 396
 		pushCmd := exec.Command(dockerBinary, "push", repoName)
397 397
 		s.trustedCmd(pushCmd)
398 398
 		out, _, err := runCommandWithOutput(pushCmd)
399
-		if err != nil {
400
-			c.Fatalf("Error running trusted push: %s\n%s", err, out)
401
-		}
402
-		if !strings.Contains(string(out), "Signing and pushing trust metadata") {
403
-			c.Fatalf("Missing expected output on trusted push with expired timestamp:\n%s", out)
404
-		}
399
+		c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out))
400
+		c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with expired timestamp"))
405 401
 	})
406 402
 }