Browse code

Checkers on integration-cli/docker_cli_commit_test

Applying #16756 to integration-cli/docker_cli_commit_test.go

Signed-off-by: Aditi Rajagopal <arajagopal@us.ibm.com>

Aditi Rajagopal authored on 2015/10/17 06:48:51
Showing 1 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/go-check/check"
7 8
 )
8 9
 
... ...
@@ -49,10 +50,9 @@ func (s *DockerSuite) TestCommitPausedContainer(c *check.C) {
49 49
 	out, _ = dockerCmd(c, "commit", cleanedContainerID)
50 50
 
51 51
 	out, err := inspectField(cleanedContainerID, "State.Paused")
52
-	c.Assert(err, check.IsNil)
53
-	if !strings.Contains(out, "true") {
54
-		c.Fatalf("commit should not unpause a paused container")
55
-	}
52
+	c.Assert(err, checker.IsNil, check.Commentf("%s", out))
53
+	// commit should not unpause a paused container
54
+	c.Assert(out, checker.Contains, "true")
56 55
 }
57 56
 
58 57
 func (s *DockerSuite) TestCommitNewFile(c *check.C) {
... ...
@@ -60,14 +60,11 @@ func (s *DockerSuite) TestCommitNewFile(c *check.C) {
60 60
 	dockerCmd(c, "run", "--name", "commiter", "busybox", "/bin/sh", "-c", "echo koye > /foo")
61 61
 
62 62
 	imageID, _ := dockerCmd(c, "commit", "commiter")
63
-	imageID = strings.Trim(imageID, "\r\n")
63
+	imageID = strings.TrimSpace(imageID)
64 64
 
65 65
 	out, _ := dockerCmd(c, "run", imageID, "cat", "/foo")
66
-
67
-	if actual := strings.Trim(out, "\r\n"); actual != "koye" {
68
-		c.Fatalf("expected output koye received %q", actual)
69
-	}
70
-
66
+	actual := strings.TrimSpace(out)
67
+	c.Assert(actual, checker.Equals, "koye")
71 68
 }
72 69
 
73 70
 func (s *DockerSuite) TestCommitHardlink(c *check.C) {
... ...
@@ -76,35 +73,18 @@ func (s *DockerSuite) TestCommitHardlink(c *check.C) {
76 76
 
77 77
 	chunks := strings.Split(strings.TrimSpace(firstOutput), " ")
78 78
 	inode := chunks[0]
79
-	found := false
80
-	for _, chunk := range chunks[1:] {
81
-		if chunk == inode {
82
-			found = true
83
-			break
84
-		}
85
-	}
86
-	if !found {
87
-		c.Fatalf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:])
88
-	}
79
+	chunks = strings.SplitAfterN(strings.TrimSpace(firstOutput), " ", 2)
80
+	c.Assert(chunks[1], checker.Contains, chunks[0], check.Commentf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:]))
89 81
 
90 82
 	imageID, _ := dockerCmd(c, "commit", "hardlinks", "hardlinks")
91
-	imageID = strings.Trim(imageID, "\r\n")
83
+	imageID = strings.TrimSpace(imageID)
92 84
 
93 85
 	secondOutput, _ := dockerCmd(c, "run", "-t", "hardlinks", "ls", "-di", "file1", "file2")
94 86
 
95 87
 	chunks = strings.Split(strings.TrimSpace(secondOutput), " ")
96 88
 	inode = chunks[0]
97
-	found = false
98
-	for _, chunk := range chunks[1:] {
99
-		if chunk == inode {
100
-			found = true
101
-			break
102
-		}
103
-	}
104
-	if !found {
105
-		c.Fatalf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:])
106
-	}
107
-
89
+	chunks = strings.SplitAfterN(strings.TrimSpace(secondOutput), " ", 2)
90
+	c.Assert(chunks[1], checker.Contains, chunks[0], check.Commentf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:]))
108 91
 }
109 92
 
110 93
 func (s *DockerSuite) TestCommitTTY(c *check.C) {
... ...
@@ -112,10 +92,9 @@ func (s *DockerSuite) TestCommitTTY(c *check.C) {
112 112
 	dockerCmd(c, "run", "-t", "--name", "tty", "busybox", "/bin/ls")
113 113
 
114 114
 	imageID, _ := dockerCmd(c, "commit", "tty", "ttytest")
115
-	imageID = strings.Trim(imageID, "\r\n")
115
+	imageID = strings.TrimSpace(imageID)
116 116
 
117 117
 	dockerCmd(c, "run", "ttytest", "/bin/ls")
118
-
119 118
 }
120 119
 
121 120
 func (s *DockerSuite) TestCommitWithHostBindMount(c *check.C) {
... ...
@@ -123,10 +102,9 @@ func (s *DockerSuite) TestCommitWithHostBindMount(c *check.C) {
123 123
 	dockerCmd(c, "run", "--name", "bind-commit", "-v", "/dev/null:/winning", "busybox", "true")
124 124
 
125 125
 	imageID, _ := dockerCmd(c, "commit", "bind-commit", "bindtest")
126
-	imageID = strings.Trim(imageID, "\r\n")
126
+	imageID = strings.TrimSpace(imageID)
127 127
 
128 128
 	dockerCmd(c, "run", "bindtest", "true")
129
-
130 129
 }
131 130
 
132 131
 func (s *DockerSuite) TestCommitChange(c *check.C) {
... ...
@@ -146,7 +124,7 @@ func (s *DockerSuite) TestCommitChange(c *check.C) {
146 146
 		"--change", "VOLUME /var/lib/docker",
147 147
 		"--change", "ONBUILD /usr/local/bin/python-build --dir /app/src",
148 148
 		"test", "test-commit")
149
-	imageID = strings.Trim(imageID, "\r\n")
149
+	imageID = strings.TrimSpace(imageID)
150 150
 
151 151
 	expected := map[string]string{
152 152
 		"Config.ExposedPorts": "map[8080/tcp:{}]",
... ...
@@ -162,12 +140,11 @@ func (s *DockerSuite) TestCommitChange(c *check.C) {
162 162
 
163 163
 	for conf, value := range expected {
164 164
 		res, err := inspectField(imageID, conf)
165
-		c.Assert(err, check.IsNil)
165
+		c.Assert(err, checker.IsNil, check.Commentf("%s('%s')", conf, res))
166 166
 		if res != value {
167 167
 			c.Errorf("%s('%s'), expected %s", conf, res, value)
168 168
 		}
169 169
 	}
170
-
171 170
 }
172 171
 
173 172
 // TODO: commit --run is deprecated, remove this once --run is removed
... ...
@@ -180,22 +157,20 @@ func (s *DockerSuite) TestCommitMergeConfigRun(c *check.C) {
180 180
 	dockerCmd(c, "commit", `--run={"Cmd": ["cat", "/tmp/foo"]}`, id, "commit-test")
181 181
 
182 182
 	out, _ = dockerCmd(c, "run", "--name", name, "commit-test")
183
-	if strings.TrimSpace(out) != "testing" {
184
-		c.Fatal("run config in committed container was not merged")
185
-	}
183
+	//run config in committed container was not merged
184
+	c.Assert(strings.TrimSpace(out), checker.Equals, "testing")
186 185
 
187 186
 	type cfg struct {
188 187
 		Env []string
189 188
 		Cmd []string
190 189
 	}
191 190
 	config1 := cfg{}
192
-	if err := inspectFieldAndMarshall(id, "Config", &config1); err != nil {
193
-		c.Fatal(err)
194
-	}
191
+	err := inspectFieldAndMarshall(id, "Config", &config1)
192
+	c.Assert(err, checker.IsNil)
193
+
195 194
 	config2 := cfg{}
196
-	if err := inspectFieldAndMarshall(name, "Config", &config2); err != nil {
197
-		c.Fatal(err)
198
-	}
195
+	err = inspectFieldAndMarshall(name, "Config", &config2)
196
+	c.Assert(err, checker.IsNil)
199 197
 
200 198
 	// Env has at least PATH loaded as well here, so let's just grab the FOO one
201 199
 	var env1, env2 string
... ...
@@ -215,5 +190,4 @@ func (s *DockerSuite) TestCommitMergeConfigRun(c *check.C) {
215 215
 	if len(config1.Env) != len(config2.Env) || env1 != env2 && env2 != "" {
216 216
 		c.Fatalf("expected envs to match: %v - %v", config1.Env, config2.Env)
217 217
 	}
218
-
219 218
 }