Browse code

Use checker assert for integration-cli/docker_cli_cp_* four files.

Signed-off-by: Jian Zhang <zhangjian.fnst@cn.fujitsu.com>

Jian Zhang authored on 2015/10/23 10:19:33
Showing 4 changed files
... ...
@@ -4,6 +4,7 @@ import (
4 4
 	"os"
5 5
 	"path/filepath"
6 6
 
7
+	"github.com/docker/docker/pkg/integration/checker"
7 8
 	"github.com/go-check/check"
8 9
 )
9 10
 
... ...
@@ -24,48 +25,37 @@ import (
24 24
 // Test for error when SRC does not exist.
25 25
 func (s *DockerSuite) TestCpFromErrSrcNotExists(c *check.C) {
26 26
 	testRequires(c, DaemonIsLinux)
27
-	cID := makeTestContainer(c, testContainerOptions{})
28
-	defer deleteContainer(cID)
27
+	containerID := makeTestContainer(c, testContainerOptions{})
29 28
 
30 29
 	tmpDir := getTestDir(c, "test-cp-from-err-src-not-exists")
31 30
 	defer os.RemoveAll(tmpDir)
32 31
 
33
-	err := runDockerCp(c, containerCpPath(cID, "file1"), tmpDir)
34
-	if err == nil {
35
-		c.Fatal("expected IsNotExist error, but got nil instead")
36
-	}
32
+	err := runDockerCp(c, containerCpPath(containerID, "file1"), tmpDir)
33
+	c.Assert(err, checker.NotNil)
37 34
 
38
-	if !isCpNotExist(err) {
39
-		c.Fatalf("expected IsNotExist error, but got %T: %s", err, err)
40
-	}
35
+	c.Assert(isCpNotExist(err), checker.True, check.Commentf("expected IsNotExist error, but got %T: %s", err, err))
41 36
 }
42 37
 
43 38
 // Test for error when SRC ends in a trailing
44 39
 // path separator but it exists as a file.
45 40
 func (s *DockerSuite) TestCpFromErrSrcNotDir(c *check.C) {
46 41
 	testRequires(c, DaemonIsLinux)
47
-	cID := makeTestContainer(c, testContainerOptions{addContent: true})
48
-	defer deleteContainer(cID)
42
+	containerID := makeTestContainer(c, testContainerOptions{addContent: true})
49 43
 
50 44
 	tmpDir := getTestDir(c, "test-cp-from-err-src-not-dir")
51 45
 	defer os.RemoveAll(tmpDir)
52 46
 
53
-	err := runDockerCp(c, containerCpPathTrailingSep(cID, "file1"), tmpDir)
54
-	if err == nil {
55
-		c.Fatal("expected IsNotDir error, but got nil instead")
56
-	}
47
+	err := runDockerCp(c, containerCpPathTrailingSep(containerID, "file1"), tmpDir)
48
+	c.Assert(err, checker.NotNil)
57 49
 
58
-	if !isCpNotDir(err) {
59
-		c.Fatalf("expected IsNotDir error, but got %T: %s", err, err)
60
-	}
50
+	c.Assert(isCpNotDir(err), checker.True, check.Commentf("expected IsNotDir error, but got %T: %s", err, err))
61 51
 }
62 52
 
63 53
 // Test for error when SRC is a valid file or directory,
64 54
 // bu the DST parent directory does not exist.
65 55
 func (s *DockerSuite) TestCpFromErrDstParentNotExists(c *check.C) {
66 56
 	testRequires(c, DaemonIsLinux)
67
-	cID := makeTestContainer(c, testContainerOptions{addContent: true})
68
-	defer deleteContainer(cID)
57
+	containerID := makeTestContainer(c, testContainerOptions{addContent: true})
69 58
 
70 59
 	tmpDir := getTestDir(c, "test-cp-from-err-dst-parent-not-exists")
71 60
 	defer os.RemoveAll(tmpDir)
... ...
@@ -73,36 +63,28 @@ func (s *DockerSuite) TestCpFromErrDstParentNotExists(c *check.C) {
73 73
 	makeTestContentInDir(c, tmpDir)
74 74
 
75 75
 	// Try with a file source.
76
-	srcPath := containerCpPath(cID, "/file1")
76
+	srcPath := containerCpPath(containerID, "/file1")
77 77
 	dstPath := cpPath(tmpDir, "notExists", "file1")
78 78
 
79 79
 	err := runDockerCp(c, srcPath, dstPath)
80
-	if err == nil {
81
-		c.Fatal("expected IsNotExist error, but got nil instead")
82
-	}
80
+	c.Assert(err, checker.NotNil)
83 81
 
84
-	if !isCpNotExist(err) {
85
-		c.Fatalf("expected IsNotExist error, but got %T: %s", err, err)
86
-	}
82
+	c.Assert(isCpNotExist(err), checker.True, check.Commentf("expected IsNotExist error, but got %T: %s", err, err))
87 83
 
88 84
 	// Try with a directory source.
89
-	srcPath = containerCpPath(cID, "/dir1")
85
+	srcPath = containerCpPath(containerID, "/dir1")
90 86
 
91
-	if err := runDockerCp(c, srcPath, dstPath); err == nil {
92
-		c.Fatal("expected IsNotExist error, but got nil instead")
93
-	}
87
+	err = runDockerCp(c, srcPath, dstPath)
88
+	c.Assert(err, checker.NotNil)
94 89
 
95
-	if !isCpNotExist(err) {
96
-		c.Fatalf("expected IsNotExist error, but got %T: %s", err, err)
97
-	}
90
+	c.Assert(isCpNotExist(err), checker.True, check.Commentf("expected IsNotExist error, but got %T: %s", err, err))
98 91
 }
99 92
 
100 93
 // Test for error when DST ends in a trailing
101 94
 // path separator but exists as a file.
102 95
 func (s *DockerSuite) TestCpFromErrDstNotDir(c *check.C) {
103 96
 	testRequires(c, DaemonIsLinux)
104
-	cID := makeTestContainer(c, testContainerOptions{addContent: true})
105
-	defer deleteContainer(cID)
97
+	containerID := makeTestContainer(c, testContainerOptions{addContent: true})
106 98
 
107 99
 	tmpDir := getTestDir(c, "test-cp-from-err-dst-not-dir")
108 100
 	defer os.RemoveAll(tmpDir)
... ...
@@ -110,36 +92,28 @@ func (s *DockerSuite) TestCpFromErrDstNotDir(c *check.C) {
110 110
 	makeTestContentInDir(c, tmpDir)
111 111
 
112 112
 	// Try with a file source.
113
-	srcPath := containerCpPath(cID, "/file1")
113
+	srcPath := containerCpPath(containerID, "/file1")
114 114
 	dstPath := cpPathTrailingSep(tmpDir, "file1")
115 115
 
116 116
 	err := runDockerCp(c, srcPath, dstPath)
117
-	if err == nil {
118
-		c.Fatal("expected IsNotDir error, but got nil instead")
119
-	}
117
+	c.Assert(err, checker.NotNil)
120 118
 
121
-	if !isCpNotDir(err) {
122
-		c.Fatalf("expected IsNotDir error, but got %T: %s", err, err)
123
-	}
119
+	c.Assert(isCpNotDir(err), checker.True, check.Commentf("expected IsNotDir error, but got %T: %s", err, err))
124 120
 
125 121
 	// Try with a directory source.
126
-	srcPath = containerCpPath(cID, "/dir1")
122
+	srcPath = containerCpPath(containerID, "/dir1")
127 123
 
128
-	if err := runDockerCp(c, srcPath, dstPath); err == nil {
129
-		c.Fatal("expected IsNotDir error, but got nil instead")
130
-	}
124
+	err = runDockerCp(c, srcPath, dstPath)
125
+	c.Assert(err, checker.NotNil)
131 126
 
132
-	if !isCpNotDir(err) {
133
-		c.Fatalf("expected IsNotDir error, but got %T: %s", err, err)
134
-	}
127
+	c.Assert(isCpNotDir(err), checker.True, check.Commentf("expected IsNotDir error, but got %T: %s", err, err))
135 128
 }
136 129
 
137 130
 // Check that copying from a container to a local symlink copies to the symlink
138 131
 // target and does not overwrite the local symlink itself.
139 132
 func (s *DockerSuite) TestCpFromSymlinkDestination(c *check.C) {
140 133
 	testRequires(c, DaemonIsLinux)
141
-	cID := makeTestContainer(c, testContainerOptions{addContent: true})
142
-	defer deleteContainer(cID)
134
+	containerID := makeTestContainer(c, testContainerOptions{addContent: true})
143 135
 
144 136
 	tmpDir := getTestDir(c, "test-cp-from-err-dst-not-dir")
145 137
 	defer os.RemoveAll(tmpDir)
... ...
@@ -148,79 +122,55 @@ func (s *DockerSuite) TestCpFromSymlinkDestination(c *check.C) {
148 148
 
149 149
 	// First, copy a file from the container to a symlink to a file. This
150 150
 	// should overwrite the symlink target contents with the source contents.
151
-	srcPath := containerCpPath(cID, "/file2")
151
+	srcPath := containerCpPath(containerID, "/file2")
152 152
 	dstPath := cpPath(tmpDir, "symlinkToFile1")
153 153
 
154
-	if err := runDockerCp(c, srcPath, dstPath); err != nil {
155
-		c.Fatalf("unexpected error %T: %s", err, err)
156
-	}
154
+	c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
157 155
 
158 156
 	// The symlink should not have been modified.
159
-	if err := symlinkTargetEquals(c, dstPath, "file1"); err != nil {
160
-		c.Fatal(err)
161
-	}
157
+	c.Assert(symlinkTargetEquals(c, dstPath, "file1"), checker.IsNil)
162 158
 
163 159
 	// The file should have the contents of "file2" now.
164
-	if err := fileContentEquals(c, cpPath(tmpDir, "file1"), "file2\n"); err != nil {
165
-		c.Fatal(err)
166
-	}
160
+	c.Assert(fileContentEquals(c, cpPath(tmpDir, "file1"), "file2\n"), checker.IsNil)
167 161
 
168 162
 	// Next, copy a file from the container to a symlink to a directory. This
169 163
 	// should copy the file into the symlink target directory.
170 164
 	dstPath = cpPath(tmpDir, "symlinkToDir1")
171 165
 
172
-	if err := runDockerCp(c, srcPath, dstPath); err != nil {
173
-		c.Fatalf("unexpected error %T: %s", err, err)
174
-	}
166
+	c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
175 167
 
176 168
 	// The symlink should not have been modified.
177
-	if err := symlinkTargetEquals(c, dstPath, "dir1"); err != nil {
178
-		c.Fatal(err)
179
-	}
169
+	c.Assert(symlinkTargetEquals(c, dstPath, "dir1"), checker.IsNil)
180 170
 
181 171
 	// The file should have the contents of "file2" now.
182
-	if err := fileContentEquals(c, cpPath(tmpDir, "file2"), "file2\n"); err != nil {
183
-		c.Fatal(err)
184
-	}
172
+	c.Assert(fileContentEquals(c, cpPath(tmpDir, "file2"), "file2\n"), checker.IsNil)
185 173
 
186 174
 	// Next, copy a file from the container to a symlink to a file that does
187 175
 	// not exist (a broken symlink). This should create the target file with
188 176
 	// the contents of the source file.
189 177
 	dstPath = cpPath(tmpDir, "brokenSymlinkToFileX")
190 178
 
191
-	if err := runDockerCp(c, srcPath, dstPath); err != nil {
192
-		c.Fatalf("unexpected error %T: %s", err, err)
193
-	}
179
+	c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
194 180
 
195 181
 	// The symlink should not have been modified.
196
-	if err := symlinkTargetEquals(c, dstPath, "fileX"); err != nil {
197
-		c.Fatal(err)
198
-	}
182
+	c.Assert(symlinkTargetEquals(c, dstPath, "fileX"), checker.IsNil)
199 183
 
200 184
 	// The file should have the contents of "file2" now.
201
-	if err := fileContentEquals(c, cpPath(tmpDir, "fileX"), "file2\n"); err != nil {
202
-		c.Fatal(err)
203
-	}
185
+	c.Assert(fileContentEquals(c, cpPath(tmpDir, "fileX"), "file2\n"), checker.IsNil)
204 186
 
205 187
 	// Next, copy a directory from the container to a symlink to a local
206 188
 	// directory. This should copy the directory into the symlink target
207 189
 	// directory and not modify the symlink.
208
-	srcPath = containerCpPath(cID, "/dir2")
190
+	srcPath = containerCpPath(containerID, "/dir2")
209 191
 	dstPath = cpPath(tmpDir, "symlinkToDir1")
210 192
 
211
-	if err := runDockerCp(c, srcPath, dstPath); err != nil {
212
-		c.Fatalf("unexpected error %T: %s", err, err)
213
-	}
193
+	c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
214 194
 
215 195
 	// The symlink should not have been modified.
216
-	if err := symlinkTargetEquals(c, dstPath, "dir1"); err != nil {
217
-		c.Fatal(err)
218
-	}
196
+	c.Assert(symlinkTargetEquals(c, dstPath, "dir1"), checker.IsNil)
219 197
 
220 198
 	// The directory should now contain a copy of "dir2".
221
-	if err := fileContentEquals(c, cpPath(tmpDir, "dir1/dir2/file2-1"), "file2-1\n"); err != nil {
222
-		c.Fatal(err)
223
-	}
199
+	c.Assert(fileContentEquals(c, cpPath(tmpDir, "dir1/dir2/file2-1"), "file2-1\n"), checker.IsNil)
224 200
 
225 201
 	// Next, copy a directory from the container to a symlink to a local
226 202
 	// directory that does not exist (a broken symlink). This should create
... ...
@@ -228,19 +178,13 @@ func (s *DockerSuite) TestCpFromSymlinkDestination(c *check.C) {
228 228
 	// should not modify the symlink.
229 229
 	dstPath = cpPath(tmpDir, "brokenSymlinkToDirX")
230 230
 
231
-	if err := runDockerCp(c, srcPath, dstPath); err != nil {
232
-		c.Fatalf("unexpected error %T: %s", err, err)
233
-	}
231
+	c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
234 232
 
235 233
 	// The symlink should not have been modified.
236
-	if err := symlinkTargetEquals(c, dstPath, "dirX"); err != nil {
237
-		c.Fatal(err)
238
-	}
234
+	c.Assert(symlinkTargetEquals(c, dstPath, "dirX"), checker.IsNil)
239 235
 
240 236
 	// The "dirX" directory should now be a copy of "dir2".
241
-	if err := fileContentEquals(c, cpPath(tmpDir, "dirX/file2-1"), "file2-1\n"); err != nil {
242
-		c.Fatal(err)
243
-	}
237
+	c.Assert(fileContentEquals(c, cpPath(tmpDir, "dirX/file2-1"), "file2-1\n"), checker.IsNil)
244 238
 }
245 239
 
246 240
 // Possibilities are reduced to the remaining 10 cases:
... ...
@@ -264,24 +208,19 @@ func (s *DockerSuite) TestCpFromSymlinkDestination(c *check.C) {
264 264
 //    contents of the source file into it.
265 265
 func (s *DockerSuite) TestCpFromCaseA(c *check.C) {
266 266
 	testRequires(c, DaemonIsLinux)
267
-	cID := makeTestContainer(c, testContainerOptions{
267
+	containerID := makeTestContainer(c, testContainerOptions{
268 268
 		addContent: true, workDir: "/root",
269 269
 	})
270
-	defer deleteContainer(cID)
271 270
 
272 271
 	tmpDir := getTestDir(c, "test-cp-from-case-a")
273 272
 	defer os.RemoveAll(tmpDir)
274 273
 
275
-	srcPath := containerCpPath(cID, "/root/file1")
274
+	srcPath := containerCpPath(containerID, "/root/file1")
276 275
 	dstPath := cpPath(tmpDir, "itWorks.txt")
277 276
 
278
-	if err := runDockerCp(c, srcPath, dstPath); err != nil {
279
-		c.Fatalf("unexpected error %T: %s", err, err)
280
-	}
277
+	c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
281 278
 
282
-	if err := fileContentEquals(c, dstPath, "file1\n"); err != nil {
283
-		c.Fatal(err)
284
-	}
279
+	c.Assert(fileContentEquals(c, dstPath, "file1\n"), checker.IsNil)
285 280
 }
286 281
 
287 282
 // B. SRC specifies a file and DST (with trailing path separator) doesn't
... ...
@@ -289,54 +228,42 @@ func (s *DockerSuite) TestCpFromCaseA(c *check.C) {
289 289
 //    create a directory when copying a single file.
290 290
 func (s *DockerSuite) TestCpFromCaseB(c *check.C) {
291 291
 	testRequires(c, DaemonIsLinux)
292
-	cID := makeTestContainer(c, testContainerOptions{addContent: true})
293
-	defer deleteContainer(cID)
292
+	containerID := makeTestContainer(c, testContainerOptions{addContent: true})
294 293
 
295 294
 	tmpDir := getTestDir(c, "test-cp-from-case-b")
296 295
 	defer os.RemoveAll(tmpDir)
297 296
 
298
-	srcPath := containerCpPath(cID, "/file1")
297
+	srcPath := containerCpPath(containerID, "/file1")
299 298
 	dstDir := cpPathTrailingSep(tmpDir, "testDir")
300 299
 
301 300
 	err := runDockerCp(c, srcPath, dstDir)
302
-	if err == nil {
303
-		c.Fatal("expected DirNotExists error, but got nil instead")
304
-	}
301
+	c.Assert(err, checker.NotNil)
305 302
 
306
-	if !isCpDirNotExist(err) {
307
-		c.Fatalf("expected DirNotExists error, but got %T: %s", err, err)
308
-	}
303
+	c.Assert(isCpDirNotExist(err), checker.True, check.Commentf("expected DirNotExists error, but got %T: %s", err, err))
309 304
 }
310 305
 
311 306
 // C. SRC specifies a file and DST exists as a file. This should overwrite
312 307
 //    the file at DST with the contents of the source file.
313 308
 func (s *DockerSuite) TestCpFromCaseC(c *check.C) {
314 309
 	testRequires(c, DaemonIsLinux)
315
-	cID := makeTestContainer(c, testContainerOptions{
310
+	containerID := makeTestContainer(c, testContainerOptions{
316 311
 		addContent: true, workDir: "/root",
317 312
 	})
318
-	defer deleteContainer(cID)
319 313
 
320 314
 	tmpDir := getTestDir(c, "test-cp-from-case-c")
321 315
 	defer os.RemoveAll(tmpDir)
322 316
 
323 317
 	makeTestContentInDir(c, tmpDir)
324 318
 
325
-	srcPath := containerCpPath(cID, "/root/file1")
319
+	srcPath := containerCpPath(containerID, "/root/file1")
326 320
 	dstPath := cpPath(tmpDir, "file2")
327 321
 
328 322
 	// Ensure the local file starts with different content.
329
-	if err := fileContentEquals(c, dstPath, "file2\n"); err != nil {
330
-		c.Fatal(err)
331
-	}
323
+	c.Assert(fileContentEquals(c, dstPath, "file2\n"), checker.IsNil)
332 324
 
333
-	if err := runDockerCp(c, srcPath, dstPath); err != nil {
334
-		c.Fatalf("unexpected error %T: %s", err, err)
335
-	}
325
+	c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
336 326
 
337
-	if err := fileContentEquals(c, dstPath, "file1\n"); err != nil {
338
-		c.Fatal(err)
339
-	}
327
+	c.Assert(fileContentEquals(c, dstPath, "file1\n"), checker.IsNil)
340 328
 }
341 329
 
342 330
 // D. SRC specifies a file and DST exists as a directory. This should place
... ...
@@ -344,50 +271,38 @@ func (s *DockerSuite) TestCpFromCaseC(c *check.C) {
344 344
 //    this works whether DST has a trailing path separator or not.
345 345
 func (s *DockerSuite) TestCpFromCaseD(c *check.C) {
346 346
 	testRequires(c, DaemonIsLinux)
347
-	cID := makeTestContainer(c, testContainerOptions{addContent: true})
348
-	defer deleteContainer(cID)
347
+	containerID := makeTestContainer(c, testContainerOptions{addContent: true})
349 348
 
350 349
 	tmpDir := getTestDir(c, "test-cp-from-case-d")
351 350
 	defer os.RemoveAll(tmpDir)
352 351
 
353 352
 	makeTestContentInDir(c, tmpDir)
354 353
 
355
-	srcPath := containerCpPath(cID, "/file1")
354
+	srcPath := containerCpPath(containerID, "/file1")
356 355
 	dstDir := cpPath(tmpDir, "dir1")
357 356
 	dstPath := filepath.Join(dstDir, "file1")
358 357
 
359 358
 	// Ensure that dstPath doesn't exist.
360
-	if _, err := os.Stat(dstPath); !os.IsNotExist(err) {
361
-		c.Fatalf("did not expect dstPath %q to exist", dstPath)
362
-	}
359
+	_, err := os.Stat(dstPath)
360
+	c.Assert(os.IsNotExist(err), checker.True, check.Commentf("did not expect dstPath %q to exist", dstPath))
363 361
 
364
-	if err := runDockerCp(c, srcPath, dstDir); err != nil {
365
-		c.Fatalf("unexpected error %T: %s", err, err)
366
-	}
362
+	c.Assert(runDockerCp(c, srcPath, dstDir), checker.IsNil)
367 363
 
368
-	if err := fileContentEquals(c, dstPath, "file1\n"); err != nil {
369
-		c.Fatal(err)
370
-	}
364
+	c.Assert(fileContentEquals(c, dstPath, "file1\n"), checker.IsNil)
371 365
 
372 366
 	// Now try again but using a trailing path separator for dstDir.
373 367
 
374
-	if err := os.RemoveAll(dstDir); err != nil {
375
-		c.Fatalf("unable to remove dstDir: %s", err)
376
-	}
368
+	// unable to remove dstDir
369
+	c.Assert(os.RemoveAll(dstDir), checker.IsNil)
377 370
 
378
-	if err := os.MkdirAll(dstDir, os.FileMode(0755)); err != nil {
379
-		c.Fatalf("unable to make dstDir: %s", err)
380
-	}
371
+	// unable to make dstDir
372
+	c.Assert(os.MkdirAll(dstDir, os.FileMode(0755)), checker.IsNil)
381 373
 
382 374
 	dstDir = cpPathTrailingSep(tmpDir, "dir1")
383 375
 
384
-	if err := runDockerCp(c, srcPath, dstDir); err != nil {
385
-		c.Fatalf("unexpected error %T: %s", err, err)
386
-	}
376
+	c.Assert(runDockerCp(c, srcPath, dstDir), checker.IsNil)
387 377
 
388
-	if err := fileContentEquals(c, dstPath, "file1\n"); err != nil {
389
-		c.Fatal(err)
390
-	}
378
+	c.Assert(fileContentEquals(c, dstPath, "file1\n"), checker.IsNil)
391 379
 }
392 380
 
393 381
 // E. SRC specifies a directory and DST does not exist. This should create a
... ...
@@ -396,66 +311,51 @@ func (s *DockerSuite) TestCpFromCaseD(c *check.C) {
396 396
 //    not.
397 397
 func (s *DockerSuite) TestCpFromCaseE(c *check.C) {
398 398
 	testRequires(c, DaemonIsLinux)
399
-	cID := makeTestContainer(c, testContainerOptions{addContent: true})
400
-	defer deleteContainer(cID)
399
+	containerID := makeTestContainer(c, testContainerOptions{addContent: true})
401 400
 
402 401
 	tmpDir := getTestDir(c, "test-cp-from-case-e")
403 402
 	defer os.RemoveAll(tmpDir)
404 403
 
405
-	srcDir := containerCpPath(cID, "dir1")
404
+	srcDir := containerCpPath(containerID, "dir1")
406 405
 	dstDir := cpPath(tmpDir, "testDir")
407 406
 	dstPath := filepath.Join(dstDir, "file1-1")
408 407
 
409
-	if err := runDockerCp(c, srcDir, dstDir); err != nil {
410
-		c.Fatalf("unexpected error %T: %s", err, err)
411
-	}
408
+	c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
412 409
 
413
-	if err := fileContentEquals(c, dstPath, "file1-1\n"); err != nil {
414
-		c.Fatal(err)
415
-	}
410
+	c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
416 411
 
417 412
 	// Now try again but using a trailing path separator for dstDir.
418 413
 
419
-	if err := os.RemoveAll(dstDir); err != nil {
420
-		c.Fatalf("unable to remove dstDir: %s", err)
421
-	}
414
+	// unable to remove dstDir
415
+	c.Assert(os.RemoveAll(dstDir), checker.IsNil)
422 416
 
423 417
 	dstDir = cpPathTrailingSep(tmpDir, "testDir")
424 418
 
425
-	if err := runDockerCp(c, srcDir, dstDir); err != nil {
426
-		c.Fatalf("unexpected error %T: %s", err, err)
427
-	}
419
+	c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
428 420
 
429
-	if err := fileContentEquals(c, dstPath, "file1-1\n"); err != nil {
430
-		c.Fatal(err)
431
-	}
421
+	c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
432 422
 }
433 423
 
434 424
 // F. SRC specifies a directory and DST exists as a file. This should cause an
435 425
 //    error as it is not possible to overwrite a file with a directory.
436 426
 func (s *DockerSuite) TestCpFromCaseF(c *check.C) {
437 427
 	testRequires(c, DaemonIsLinux)
438
-	cID := makeTestContainer(c, testContainerOptions{
428
+	containerID := makeTestContainer(c, testContainerOptions{
439 429
 		addContent: true, workDir: "/root",
440 430
 	})
441
-	defer deleteContainer(cID)
442 431
 
443 432
 	tmpDir := getTestDir(c, "test-cp-from-case-f")
444 433
 	defer os.RemoveAll(tmpDir)
445 434
 
446 435
 	makeTestContentInDir(c, tmpDir)
447 436
 
448
-	srcDir := containerCpPath(cID, "/root/dir1")
437
+	srcDir := containerCpPath(containerID, "/root/dir1")
449 438
 	dstFile := cpPath(tmpDir, "file1")
450 439
 
451 440
 	err := runDockerCp(c, srcDir, dstFile)
452
-	if err == nil {
453
-		c.Fatal("expected ErrCannotCopyDir error, but got nil instead")
454
-	}
441
+	c.Assert(err, checker.NotNil)
455 442
 
456
-	if !isCpCannotCopyDir(err) {
457
-		c.Fatalf("expected ErrCannotCopyDir error, but got %T: %s", err, err)
458
-	}
443
+	c.Assert(isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
459 444
 }
460 445
 
461 446
 // G. SRC specifies a directory and DST exists as a directory. This should copy
... ...
@@ -463,48 +363,37 @@ func (s *DockerSuite) TestCpFromCaseF(c *check.C) {
463 463
 //    works whether DST has a trailing path separator or not.
464 464
 func (s *DockerSuite) TestCpFromCaseG(c *check.C) {
465 465
 	testRequires(c, DaemonIsLinux)
466
-	cID := makeTestContainer(c, testContainerOptions{
466
+	containerID := makeTestContainer(c, testContainerOptions{
467 467
 		addContent: true, workDir: "/root",
468 468
 	})
469
-	defer deleteContainer(cID)
470 469
 
471 470
 	tmpDir := getTestDir(c, "test-cp-from-case-g")
472 471
 	defer os.RemoveAll(tmpDir)
473 472
 
474 473
 	makeTestContentInDir(c, tmpDir)
475 474
 
476
-	srcDir := containerCpPath(cID, "/root/dir1")
475
+	srcDir := containerCpPath(containerID, "/root/dir1")
477 476
 	dstDir := cpPath(tmpDir, "dir2")
478 477
 	resultDir := filepath.Join(dstDir, "dir1")
479 478
 	dstPath := filepath.Join(resultDir, "file1-1")
480 479
 
481
-	if err := runDockerCp(c, srcDir, dstDir); err != nil {
482
-		c.Fatalf("unexpected error %T: %s", err, err)
483
-	}
480
+	c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
484 481
 
485
-	if err := fileContentEquals(c, dstPath, "file1-1\n"); err != nil {
486
-		c.Fatal(err)
487
-	}
482
+	c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
488 483
 
489 484
 	// Now try again but using a trailing path separator for dstDir.
490 485
 
491
-	if err := os.RemoveAll(dstDir); err != nil {
492
-		c.Fatalf("unable to remove dstDir: %s", err)
493
-	}
486
+	// unable to remove dstDir
487
+	c.Assert(os.RemoveAll(dstDir), checker.IsNil)
494 488
 
495
-	if err := os.MkdirAll(dstDir, os.FileMode(0755)); err != nil {
496
-		c.Fatalf("unable to make dstDir: %s", err)
497
-	}
489
+	// unable to make dstDir
490
+	c.Assert(os.MkdirAll(dstDir, os.FileMode(0755)), checker.IsNil)
498 491
 
499 492
 	dstDir = cpPathTrailingSep(tmpDir, "dir2")
500 493
 
501
-	if err := runDockerCp(c, srcDir, dstDir); err != nil {
502
-		c.Fatalf("unexpected error %T: %s", err, err)
503
-	}
494
+	c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
504 495
 
505
-	if err := fileContentEquals(c, dstPath, "file1-1\n"); err != nil {
506
-		c.Fatal(err)
507
-	}
496
+	c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
508 497
 }
509 498
 
510 499
 // H. SRC specifies a directory's contents only and DST does not exist. This
... ...
@@ -513,39 +402,29 @@ func (s *DockerSuite) TestCpFromCaseG(c *check.C) {
513 513
 //    this works whether DST has a trailing path separator or not.
514 514
 func (s *DockerSuite) TestCpFromCaseH(c *check.C) {
515 515
 	testRequires(c, DaemonIsLinux)
516
-	cID := makeTestContainer(c, testContainerOptions{addContent: true})
517
-	defer deleteContainer(cID)
516
+	containerID := makeTestContainer(c, testContainerOptions{addContent: true})
518 517
 
519 518
 	tmpDir := getTestDir(c, "test-cp-from-case-h")
520 519
 	defer os.RemoveAll(tmpDir)
521 520
 
522
-	srcDir := containerCpPathTrailingSep(cID, "dir1") + "."
521
+	srcDir := containerCpPathTrailingSep(containerID, "dir1") + "."
523 522
 	dstDir := cpPath(tmpDir, "testDir")
524 523
 	dstPath := filepath.Join(dstDir, "file1-1")
525 524
 
526
-	if err := runDockerCp(c, srcDir, dstDir); err != nil {
527
-		c.Fatalf("unexpected error %T: %s", err, err)
528
-	}
525
+	c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
529 526
 
530
-	if err := fileContentEquals(c, dstPath, "file1-1\n"); err != nil {
531
-		c.Fatal(err)
532
-	}
527
+	c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
533 528
 
534 529
 	// Now try again but using a trailing path separator for dstDir.
535 530
 
536
-	if err := os.RemoveAll(dstDir); err != nil {
537
-		c.Fatalf("unable to remove resultDir: %s", err)
538
-	}
531
+	// unable to remove resultDir
532
+	c.Assert(os.RemoveAll(dstDir), checker.IsNil)
539 533
 
540 534
 	dstDir = cpPathTrailingSep(tmpDir, "testDir")
541 535
 
542
-	if err := runDockerCp(c, srcDir, dstDir); err != nil {
543
-		c.Fatalf("unexpected error %T: %s", err, err)
544
-	}
536
+	c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
545 537
 
546
-	if err := fileContentEquals(c, dstPath, "file1-1\n"); err != nil {
547
-		c.Fatal(err)
548
-	}
538
+	c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
549 539
 }
550 540
 
551 541
 // I. SRC specifies a directory's contents only and DST exists as a file. This
... ...
@@ -553,27 +432,22 @@ func (s *DockerSuite) TestCpFromCaseH(c *check.C) {
553 553
 //    directory.
554 554
 func (s *DockerSuite) TestCpFromCaseI(c *check.C) {
555 555
 	testRequires(c, DaemonIsLinux)
556
-	cID := makeTestContainer(c, testContainerOptions{
556
+	containerID := makeTestContainer(c, testContainerOptions{
557 557
 		addContent: true, workDir: "/root",
558 558
 	})
559
-	defer deleteContainer(cID)
560 559
 
561 560
 	tmpDir := getTestDir(c, "test-cp-from-case-i")
562 561
 	defer os.RemoveAll(tmpDir)
563 562
 
564 563
 	makeTestContentInDir(c, tmpDir)
565 564
 
566
-	srcDir := containerCpPathTrailingSep(cID, "/root/dir1") + "."
565
+	srcDir := containerCpPathTrailingSep(containerID, "/root/dir1") + "."
567 566
 	dstFile := cpPath(tmpDir, "file1")
568 567
 
569 568
 	err := runDockerCp(c, srcDir, dstFile)
570
-	if err == nil {
571
-		c.Fatal("expected ErrCannotCopyDir error, but got nil instead")
572
-	}
569
+	c.Assert(err, checker.NotNil)
573 570
 
574
-	if !isCpCannotCopyDir(err) {
575
-		c.Fatalf("expected ErrCannotCopyDir error, but got %T: %s", err, err)
576
-	}
571
+	c.Assert(isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
577 572
 }
578 573
 
579 574
 // J. SRC specifies a directory's contents only and DST exists as a directory.
... ...
@@ -582,45 +456,34 @@ func (s *DockerSuite) TestCpFromCaseI(c *check.C) {
582 582
 //    trailing path separator or not.
583 583
 func (s *DockerSuite) TestCpFromCaseJ(c *check.C) {
584 584
 	testRequires(c, DaemonIsLinux)
585
-	cID := makeTestContainer(c, testContainerOptions{
585
+	containerID := makeTestContainer(c, testContainerOptions{
586 586
 		addContent: true, workDir: "/root",
587 587
 	})
588
-	defer deleteContainer(cID)
589 588
 
590 589
 	tmpDir := getTestDir(c, "test-cp-from-case-j")
591 590
 	defer os.RemoveAll(tmpDir)
592 591
 
593 592
 	makeTestContentInDir(c, tmpDir)
594 593
 
595
-	srcDir := containerCpPathTrailingSep(cID, "/root/dir1") + "."
594
+	srcDir := containerCpPathTrailingSep(containerID, "/root/dir1") + "."
596 595
 	dstDir := cpPath(tmpDir, "dir2")
597 596
 	dstPath := filepath.Join(dstDir, "file1-1")
598 597
 
599
-	if err := runDockerCp(c, srcDir, dstDir); err != nil {
600
-		c.Fatalf("unexpected error %T: %s", err, err)
601
-	}
598
+	c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
602 599
 
603
-	if err := fileContentEquals(c, dstPath, "file1-1\n"); err != nil {
604
-		c.Fatal(err)
605
-	}
600
+	c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
606 601
 
607 602
 	// Now try again but using a trailing path separator for dstDir.
608 603
 
609
-	if err := os.RemoveAll(dstDir); err != nil {
610
-		c.Fatalf("unable to remove dstDir: %s", err)
611
-	}
604
+	// unable to remove dstDir
605
+	c.Assert(os.RemoveAll(dstDir), checker.IsNil)
612 606
 
613
-	if err := os.MkdirAll(dstDir, os.FileMode(0755)); err != nil {
614
-		c.Fatalf("unable to make dstDir: %s", err)
615
-	}
607
+	// unable to make dstDir
608
+	c.Assert(os.MkdirAll(dstDir, os.FileMode(0755)), checker.IsNil)
616 609
 
617 610
 	dstDir = cpPathTrailingSep(tmpDir, "dir2")
618 611
 
619
-	if err := runDockerCp(c, srcDir, dstDir); err != nil {
620
-		c.Fatalf("unexpected error %T: %s", err, err)
621
-	}
612
+	c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
622 613
 
623
-	if err := fileContentEquals(c, dstPath, "file1-1\n"); err != nil {
624
-		c.Fatal(err)
625
-	}
614
+	c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
626 615
 }
... ...
@@ -10,6 +10,7 @@ import (
10 10
 	"path/filepath"
11 11
 	"strings"
12 12
 
13
+	"github.com/docker/docker/pkg/integration/checker"
13 14
 	"github.com/go-check/check"
14 15
 )
15 16
 
... ...
@@ -26,107 +27,77 @@ const (
26 26
 // Ensure that an all-local path case returns an error.
27 27
 func (s *DockerSuite) TestCpLocalOnly(c *check.C) {
28 28
 	err := runDockerCp(c, "foo", "bar")
29
-	if err == nil {
30
-		c.Fatal("expected failure, got success")
31
-	}
29
+	c.Assert(err, checker.NotNil)
32 30
 
33
-	if !strings.Contains(err.Error(), "must specify at least one container source") {
34
-		c.Fatalf("unexpected output: %s", err.Error())
35
-	}
31
+	c.Assert(err.Error(), checker.Contains, "must specify at least one container source")
36 32
 }
37 33
 
38 34
 // Test for #5656
39 35
 // Check that garbage paths don't escape the container's rootfs
40 36
 func (s *DockerSuite) TestCpGarbagePath(c *check.C) {
41 37
 	testRequires(c, DaemonIsLinux)
42
-	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
43
-	if exitCode != 0 {
44
-		c.Fatal("failed to create a container", out)
45
-	}
38
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
46 39
 
47
-	cleanedContainerID := strings.TrimSpace(out)
40
+	containerID := strings.TrimSpace(out)
48 41
 
49
-	out, _ = dockerCmd(c, "wait", cleanedContainerID)
50
-	if strings.TrimSpace(out) != "0" {
51
-		c.Fatal("failed to set up container", out)
52
-	}
42
+	out, _ = dockerCmd(c, "wait", containerID)
43
+	// failed to set up container
44
+	c.Assert(strings.TrimSpace(out), checker.Equals, "0")
53 45
 
54
-	if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
55
-		c.Fatal(err)
56
-	}
46
+	c.Assert(os.MkdirAll(cpTestPath, os.ModeDir), checker.IsNil)
57 47
 
58 48
 	hostFile, err := os.Create(cpFullPath)
59
-	if err != nil {
60
-		c.Fatal(err)
61
-	}
49
+	c.Assert(err, checker.IsNil)
62 50
 	defer hostFile.Close()
63 51
 	defer os.RemoveAll(cpTestPathParent)
64 52
 
65 53
 	fmt.Fprintf(hostFile, "%s", cpHostContents)
66 54
 
67 55
 	tmpdir, err := ioutil.TempDir("", "docker-integration")
68
-	if err != nil {
69
-		c.Fatal(err)
70
-	}
56
+	c.Assert(err, checker.IsNil)
71 57
 
72 58
 	tmpname := filepath.Join(tmpdir, cpTestName)
73 59
 	defer os.RemoveAll(tmpdir)
74 60
 
75 61
 	path := path.Join("../../../../../../../../../../../../", cpFullPath)
76 62
 
77
-	dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
63
+	dockerCmd(c, "cp", containerID+":"+path, tmpdir)
78 64
 
79 65
 	file, _ := os.Open(tmpname)
80 66
 	defer file.Close()
81 67
 
82 68
 	test, err := ioutil.ReadAll(file)
83
-	if err != nil {
84
-		c.Fatal(err)
85
-	}
86
-
87
-	if string(test) == cpHostContents {
88
-		c.Errorf("output matched host file -- garbage path can escape container rootfs")
89
-	}
69
+	c.Assert(err, checker.IsNil)
90 70
 
91
-	if string(test) != cpContainerContents {
92
-		c.Errorf("output doesn't match the input for garbage path")
93
-	}
71
+	// output matched host file -- garbage path can escape container rootfs
72
+	c.Assert(string(test), checker.Not(checker.Equals), cpHostContents)
94 73
 
74
+	// output doesn't match the input for garbage path
75
+	c.Assert(string(test), checker.Equals, cpContainerContents)
95 76
 }
96 77
 
97 78
 // Check that relative paths are relative to the container's rootfs
98 79
 func (s *DockerSuite) TestCpRelativePath(c *check.C) {
99 80
 	testRequires(c, DaemonIsLinux)
100
-	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
101
-	if exitCode != 0 {
102
-		c.Fatal("failed to create a container", out)
103
-	}
81
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
104 82
 
105
-	cleanedContainerID := strings.TrimSpace(out)
83
+	containerID := strings.TrimSpace(out)
106 84
 
107
-	out, _ = dockerCmd(c, "wait", cleanedContainerID)
108
-	if strings.TrimSpace(out) != "0" {
109
-		c.Fatal("failed to set up container", out)
110
-	}
85
+	out, _ = dockerCmd(c, "wait", containerID)
86
+	// failed to set up container
87
+	c.Assert(strings.TrimSpace(out), checker.Equals, "0")
111 88
 
112
-	if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
113
-		c.Fatal(err)
114
-	}
89
+	c.Assert(os.MkdirAll(cpTestPath, os.ModeDir), checker.IsNil)
115 90
 
116 91
 	hostFile, err := os.Create(cpFullPath)
117
-	if err != nil {
118
-		c.Fatal(err)
119
-	}
92
+	c.Assert(err, checker.IsNil)
120 93
 	defer hostFile.Close()
121 94
 	defer os.RemoveAll(cpTestPathParent)
122 95
 
123 96
 	fmt.Fprintf(hostFile, "%s", cpHostContents)
124 97
 
125 98
 	tmpdir, err := ioutil.TempDir("", "docker-integration")
126
-
127
-	if err != nil {
128
-		c.Fatal(err)
129
-	}
99
+	c.Assert(err, checker.IsNil)
130 100
 
131 101
 	tmpname := filepath.Join(tmpdir, cpTestName)
132 102
 	defer os.RemoveAll(tmpdir)
... ...
@@ -136,200 +107,151 @@ func (s *DockerSuite) TestCpRelativePath(c *check.C) {
136 136
 		// normally this is `filepath.Rel("/", cpFullPath)` but we cannot
137 137
 		// get this unix-path manipulation on windows with filepath.
138 138
 		relPath = cpFullPath[1:]
139
-	} else {
140
-		c.Fatalf("path %s was assumed to be an absolute path", cpFullPath)
141 139
 	}
140
+	c.Assert(path.IsAbs(cpFullPath), checker.True, check.Commentf("path %s was assumed to be an absolute path", cpFullPath))
142 141
 
143
-	dockerCmd(c, "cp", cleanedContainerID+":"+relPath, tmpdir)
142
+	dockerCmd(c, "cp", containerID+":"+relPath, tmpdir)
144 143
 
145 144
 	file, _ := os.Open(tmpname)
146 145
 	defer file.Close()
147 146
 
148 147
 	test, err := ioutil.ReadAll(file)
149
-	if err != nil {
150
-		c.Fatal(err)
151
-	}
152
-
153
-	if string(test) == cpHostContents {
154
-		c.Errorf("output matched host file -- relative path can escape container rootfs")
155
-	}
148
+	c.Assert(err, checker.IsNil)
156 149
 
157
-	if string(test) != cpContainerContents {
158
-		c.Errorf("output doesn't match the input for relative path")
159
-	}
150
+	// output matched host file -- relative path can escape container rootfs
151
+	c.Assert(string(test), checker.Not(checker.Equals), cpHostContents)
160 152
 
153
+	// output doesn't match the input for relative path
154
+	c.Assert(string(test), checker.Equals, cpContainerContents)
161 155
 }
162 156
 
163 157
 // Check that absolute paths are relative to the container's rootfs
164 158
 func (s *DockerSuite) TestCpAbsolutePath(c *check.C) {
165 159
 	testRequires(c, DaemonIsLinux)
166
-	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
167
-	if exitCode != 0 {
168
-		c.Fatal("failed to create a container", out)
169
-	}
160
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
170 161
 
171
-	cleanedContainerID := strings.TrimSpace(out)
162
+	containerID := strings.TrimSpace(out)
172 163
 
173
-	out, _ = dockerCmd(c, "wait", cleanedContainerID)
174
-	if strings.TrimSpace(out) != "0" {
175
-		c.Fatal("failed to set up container", out)
176
-	}
164
+	out, _ = dockerCmd(c, "wait", containerID)
165
+	// failed to set up container
166
+	c.Assert(strings.TrimSpace(out), checker.Equals, "0")
177 167
 
178
-	if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
179
-		c.Fatal(err)
180
-	}
168
+	c.Assert(os.MkdirAll(cpTestPath, os.ModeDir), checker.IsNil)
181 169
 
182 170
 	hostFile, err := os.Create(cpFullPath)
183
-	if err != nil {
184
-		c.Fatal(err)
185
-	}
171
+	c.Assert(err, checker.IsNil)
186 172
 	defer hostFile.Close()
187 173
 	defer os.RemoveAll(cpTestPathParent)
188 174
 
189 175
 	fmt.Fprintf(hostFile, "%s", cpHostContents)
190 176
 
191 177
 	tmpdir, err := ioutil.TempDir("", "docker-integration")
192
-
193
-	if err != nil {
194
-		c.Fatal(err)
195
-	}
178
+	c.Assert(err, checker.IsNil)
196 179
 
197 180
 	tmpname := filepath.Join(tmpdir, cpTestName)
198 181
 	defer os.RemoveAll(tmpdir)
199 182
 
200 183
 	path := cpFullPath
201 184
 
202
-	dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
185
+	dockerCmd(c, "cp", containerID+":"+path, tmpdir)
203 186
 
204 187
 	file, _ := os.Open(tmpname)
205 188
 	defer file.Close()
206 189
 
207 190
 	test, err := ioutil.ReadAll(file)
208
-	if err != nil {
209
-		c.Fatal(err)
210
-	}
211
-
212
-	if string(test) == cpHostContents {
213
-		c.Errorf("output matched host file -- absolute path can escape container rootfs")
214
-	}
191
+	c.Assert(err, checker.IsNil)
215 192
 
216
-	if string(test) != cpContainerContents {
217
-		c.Errorf("output doesn't match the input for absolute path")
218
-	}
193
+	// output matched host file -- absolute path can escape container rootfs
194
+	c.Assert(string(test), checker.Not(checker.Equals), cpHostContents)
219 195
 
196
+	// output doesn't match the input for absolute path
197
+	c.Assert(string(test), checker.Equals, cpContainerContents)
220 198
 }
221 199
 
222 200
 // Test for #5619
223 201
 // Check that absolute symlinks are still relative to the container's rootfs
224 202
 func (s *DockerSuite) TestCpAbsoluteSymlink(c *check.C) {
225 203
 	testRequires(c, DaemonIsLinux)
226
-	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpFullPath+" container_path")
227
-	if exitCode != 0 {
228
-		c.Fatal("failed to create a container", out)
229
-	}
204
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpFullPath+" container_path")
230 205
 
231
-	cleanedContainerID := strings.TrimSpace(out)
206
+	containerID := strings.TrimSpace(out)
232 207
 
233
-	out, _ = dockerCmd(c, "wait", cleanedContainerID)
234
-	if strings.TrimSpace(out) != "0" {
235
-		c.Fatal("failed to set up container", out)
236
-	}
208
+	out, _ = dockerCmd(c, "wait", containerID)
209
+	// failed to set up container
210
+	c.Assert(strings.TrimSpace(out), checker.Equals, "0")
237 211
 
238
-	if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
239
-		c.Fatal(err)
240
-	}
212
+	c.Assert(os.MkdirAll(cpTestPath, os.ModeDir), checker.IsNil)
241 213
 
242 214
 	hostFile, err := os.Create(cpFullPath)
243
-	if err != nil {
244
-		c.Fatal(err)
245
-	}
215
+	c.Assert(err, checker.IsNil)
246 216
 	defer hostFile.Close()
247 217
 	defer os.RemoveAll(cpTestPathParent)
248 218
 
249 219
 	fmt.Fprintf(hostFile, "%s", cpHostContents)
250 220
 
251 221
 	tmpdir, err := ioutil.TempDir("", "docker-integration")
252
-
253
-	if err != nil {
254
-		c.Fatal(err)
255
-	}
222
+	c.Assert(err, checker.IsNil)
256 223
 
257 224
 	tmpname := filepath.Join(tmpdir, "container_path")
258 225
 	defer os.RemoveAll(tmpdir)
259 226
 
260 227
 	path := path.Join("/", "container_path")
261 228
 
262
-	dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
229
+	dockerCmd(c, "cp", containerID+":"+path, tmpdir)
263 230
 
264 231
 	// We should have copied a symlink *NOT* the file itself!
265 232
 	linkTarget, err := os.Readlink(tmpname)
266
-	if err != nil {
267
-		c.Fatal(err)
268
-	}
233
+	c.Assert(err, checker.IsNil)
269 234
 
270
-	if linkTarget != filepath.FromSlash(cpFullPath) {
271
-		c.Errorf("symlink target was %q, but expected: %q", linkTarget, cpFullPath)
272
-	}
235
+	c.Assert(linkTarget, checker.Equals, filepath.FromSlash(cpFullPath))
273 236
 }
274 237
 
275 238
 // Check that symlinks to a directory behave as expected when copying one from
276 239
 // a container.
277 240
 func (s *DockerSuite) TestCpFromSymlinkToDirectory(c *check.C) {
278 241
 	testRequires(c, DaemonIsLinux)
279
-	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPathParent+" /dir_link")
280
-	if exitCode != 0 {
281
-		c.Fatal("failed to create a container", out)
282
-	}
242
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPathParent+" /dir_link")
283 243
 
284
-	cleanedContainerID := strings.TrimSpace(out)
244
+	containerID := strings.TrimSpace(out)
285 245
 
286
-	out, _ = dockerCmd(c, "wait", cleanedContainerID)
287
-	if strings.TrimSpace(out) != "0" {
288
-		c.Fatal("failed to set up container", out)
289
-	}
246
+	out, _ = dockerCmd(c, "wait", containerID)
247
+	// failed to set up container
248
+	c.Assert(strings.TrimSpace(out), checker.Equals, "0")
290 249
 
291 250
 	testDir, err := ioutil.TempDir("", "test-cp-from-symlink-to-dir-")
292
-	if err != nil {
293
-		c.Fatal(err)
294
-	}
251
+	c.Assert(err, checker.IsNil)
295 252
 	defer os.RemoveAll(testDir)
296 253
 
297 254
 	// This copy command should copy the symlink, not the target, into the
298 255
 	// temporary directory.
299
-	dockerCmd(c, "cp", cleanedContainerID+":"+"/dir_link", testDir)
256
+	dockerCmd(c, "cp", containerID+":"+"/dir_link", testDir)
300 257
 
301 258
 	expectedPath := filepath.Join(testDir, "dir_link")
302 259
 	linkTarget, err := os.Readlink(expectedPath)
303
-	if err != nil {
304
-		c.Fatalf("unable to read symlink at %q: %v", expectedPath, err)
305
-	}
260
+	c.Assert(err, checker.IsNil)
306 261
 
307
-	if linkTarget != filepath.FromSlash(cpTestPathParent) {
308
-		c.Errorf("symlink target was %q, but expected: %q", linkTarget, cpTestPathParent)
309
-	}
262
+	c.Assert(linkTarget, checker.Equals, filepath.FromSlash(cpTestPathParent))
310 263
 
311 264
 	os.Remove(expectedPath)
312 265
 
313 266
 	// This copy command should resolve the symlink (note the trailing
314 267
 	// separator), copying the target into the temporary directory.
315
-	dockerCmd(c, "cp", cleanedContainerID+":"+"/dir_link/", testDir)
268
+	dockerCmd(c, "cp", containerID+":"+"/dir_link/", testDir)
316 269
 
317 270
 	// It *should not* have copied the directory using the target's name, but
318 271
 	// used the given name instead.
319 272
 	unexpectedPath := filepath.Join(testDir, cpTestPathParent)
320
-	if stat, err := os.Lstat(unexpectedPath); err == nil {
321
-		c.Fatalf("target name was copied: %q - %q", stat.Mode(), stat.Name())
273
+	stat, err := os.Lstat(unexpectedPath)
274
+	if err == nil {
275
+		out = fmt.Sprintf("target name was copied: %q - %q", stat.Mode(), stat.Name())
322 276
 	}
277
+	c.Assert(err, checker.NotNil, check.Commentf(out))
323 278
 
324 279
 	// It *should* have copied the directory using the asked name "dir_link".
325
-	stat, err := os.Lstat(expectedPath)
326
-	if err != nil {
327
-		c.Fatalf("unable to stat resource at %q: %v", expectedPath, err)
328
-	}
280
+	stat, err = os.Lstat(expectedPath)
281
+	c.Assert(err, checker.IsNil, check.Commentf("unable to stat resource at %q", expectedPath))
329 282
 
330
-	if !stat.IsDir() {
331
-		c.Errorf("should have copied a directory but got %q instead", stat.Mode())
332
-	}
283
+	c.Assert(stat.IsDir(), checker.True, check.Commentf("should have copied a directory but got %q instead", stat.Mode()))
333 284
 }
334 285
 
335 286
 // Check that symlinks to a directory behave as expected when copying one to a
... ...
@@ -339,65 +261,46 @@ func (s *DockerSuite) TestCpToSymlinkToDirectory(c *check.C) {
339 339
 	testRequires(c, SameHostDaemon) // Requires local volume mount bind.
340 340
 
341 341
 	testVol, err := ioutil.TempDir("", "test-cp-to-symlink-to-dir-")
342
-	if err != nil {
343
-		c.Fatal(err)
344
-	}
342
+	c.Assert(err, checker.IsNil)
345 343
 	defer os.RemoveAll(testVol)
346 344
 
347 345
 	// Create a test container with a local volume. We will test by copying
348 346
 	// to the volume path in the container which we can then verify locally.
349
-	out, exitCode := dockerCmd(c, "create", "-v", testVol+":/testVol", "busybox")
350
-	if exitCode != 0 {
351
-		c.Fatal("failed to create a container", out)
352
-	}
347
+	out, _ := dockerCmd(c, "create", "-v", testVol+":/testVol", "busybox")
353 348
 
354
-	cleanedContainerID := strings.TrimSpace(out)
349
+	containerID := strings.TrimSpace(out)
355 350
 
356 351
 	// Create a temp directory to hold a test file nested in a direcotry.
357 352
 	testDir, err := ioutil.TempDir("", "test-cp-to-symlink-to-dir-")
358
-	if err != nil {
359
-		c.Fatal(err)
360
-	}
353
+	c.Assert(err, checker.IsNil)
361 354
 	defer os.RemoveAll(testDir)
362 355
 
363 356
 	// This file will be at "/testDir/some/path/test" and will be copied into
364 357
 	// the test volume later.
365 358
 	hostTestFilename := filepath.Join(testDir, cpFullPath)
366
-	if err := os.MkdirAll(filepath.Dir(hostTestFilename), os.FileMode(0700)); err != nil {
367
-		c.Fatal(err)
368
-	}
369
-	if err := ioutil.WriteFile(hostTestFilename, []byte(cpHostContents), os.FileMode(0600)); err != nil {
370
-		c.Fatal(err)
371
-	}
359
+	c.Assert(os.MkdirAll(filepath.Dir(hostTestFilename), os.FileMode(0700)), checker.IsNil)
360
+	c.Assert(ioutil.WriteFile(hostTestFilename, []byte(cpHostContents), os.FileMode(0600)), checker.IsNil)
372 361
 
373 362
 	// Now create another temp directory to hold a symlink to the
374 363
 	// "/testDir/some" directory.
375 364
 	linkDir, err := ioutil.TempDir("", "test-cp-to-symlink-to-dir-")
376
-	if err != nil {
377
-		c.Fatal(err)
378
-	}
365
+	c.Assert(err, checker.IsNil)
379 366
 	defer os.RemoveAll(linkDir)
380 367
 
381 368
 	// Then symlink "/linkDir/dir_link" to "/testdir/some".
382 369
 	linkTarget := filepath.Join(testDir, cpTestPathParent)
383 370
 	localLink := filepath.Join(linkDir, "dir_link")
384
-	if err := os.Symlink(linkTarget, localLink); err != nil {
385
-		c.Fatal(err)
386
-	}
371
+	c.Assert(os.Symlink(linkTarget, localLink), checker.IsNil)
387 372
 
388 373
 	// Now copy that symlink into the test volume in the container.
389
-	dockerCmd(c, "cp", localLink, cleanedContainerID+":/testVol")
374
+	dockerCmd(c, "cp", localLink, containerID+":/testVol")
390 375
 
391 376
 	// This copy command should have copied the symlink *not* the target.
392 377
 	expectedPath := filepath.Join(testVol, "dir_link")
393 378
 	actualLinkTarget, err := os.Readlink(expectedPath)
394
-	if err != nil {
395
-		c.Fatalf("unable to read symlink at %q: %v", expectedPath, err)
396
-	}
379
+	c.Assert(err, checker.IsNil, check.Commentf("unable to read symlink at %q", expectedPath))
397 380
 
398
-	if actualLinkTarget != linkTarget {
399
-		c.Errorf("symlink target was %q, but expected: %q", actualLinkTarget, linkTarget)
400
-	}
381
+	c.Assert(actualLinkTarget, checker.Equals, linkTarget)
401 382
 
402 383
 	// Good, now remove that copied link for the next test.
403 384
 	os.Remove(expectedPath)
... ...
@@ -405,62 +308,48 @@ func (s *DockerSuite) TestCpToSymlinkToDirectory(c *check.C) {
405 405
 	// This copy command should resolve the symlink (note the trailing
406 406
 	// separator), copying the target into the test volume directory in the
407 407
 	// container.
408
-	dockerCmd(c, "cp", localLink+"/", cleanedContainerID+":/testVol")
408
+	dockerCmd(c, "cp", localLink+"/", containerID+":/testVol")
409 409
 
410 410
 	// It *should not* have copied the directory using the target's name, but
411 411
 	// used the given name instead.
412 412
 	unexpectedPath := filepath.Join(testVol, cpTestPathParent)
413
-	if stat, err := os.Lstat(unexpectedPath); err == nil {
414
-		c.Fatalf("target name was copied: %q - %q", stat.Mode(), stat.Name())
413
+	stat, err := os.Lstat(unexpectedPath)
414
+	if err == nil {
415
+		out = fmt.Sprintf("target name was copied: %q - %q", stat.Mode(), stat.Name())
415 416
 	}
417
+	c.Assert(err, checker.NotNil, check.Commentf(out))
416 418
 
417 419
 	// It *should* have copied the directory using the asked name "dir_link".
418
-	stat, err := os.Lstat(expectedPath)
419
-	if err != nil {
420
-		c.Fatalf("unable to stat resource at %q: %v", expectedPath, err)
421
-	}
420
+	stat, err = os.Lstat(expectedPath)
421
+	c.Assert(err, checker.IsNil, check.Commentf("unable to stat resource at %q", expectedPath))
422 422
 
423
-	if !stat.IsDir() {
424
-		c.Errorf("should have copied a directory but got %q instead", stat.Mode())
425
-	}
423
+	c.Assert(stat.IsDir(), checker.True, check.Commentf("should have copied a directory but got %q instead", stat.Mode()))
426 424
 
427 425
 	// And this directory should contain the file copied from the host at the
428 426
 	// expected location: "/testVol/dir_link/path/test"
429 427
 	expectedFilepath := filepath.Join(testVol, "dir_link/path/test")
430 428
 	fileContents, err := ioutil.ReadFile(expectedFilepath)
431
-	if err != nil {
432
-		c.Fatal(err)
433
-	}
429
+	c.Assert(err, checker.IsNil)
434 430
 
435
-	if string(fileContents) != cpHostContents {
436
-		c.Fatalf("file contains %q but expected %q", string(fileContents), cpHostContents)
437
-	}
431
+	c.Assert(string(fileContents), checker.Equals, cpHostContents)
438 432
 }
439 433
 
440 434
 // Test for #5619
441 435
 // Check that symlinks which are part of the resource path are still relative to the container's rootfs
442 436
 func (s *DockerSuite) TestCpSymlinkComponent(c *check.C) {
443 437
 	testRequires(c, DaemonIsLinux)
444
-	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPath+" container_path")
445
-	if exitCode != 0 {
446
-		c.Fatal("failed to create a container", out)
447
-	}
438
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPath+" container_path")
448 439
 
449
-	cleanedContainerID := strings.TrimSpace(out)
440
+	containerID := strings.TrimSpace(out)
450 441
 
451
-	out, _ = dockerCmd(c, "wait", cleanedContainerID)
452
-	if strings.TrimSpace(out) != "0" {
453
-		c.Fatal("failed to set up container", out)
454
-	}
442
+	out, _ = dockerCmd(c, "wait", containerID)
443
+	// failed to set up container
444
+	c.Assert(strings.TrimSpace(out), checker.Equals, "0")
455 445
 
456
-	if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
457
-		c.Fatal(err)
458
-	}
446
+	c.Assert(os.MkdirAll(cpTestPath, os.ModeDir), checker.IsNil)
459 447
 
460 448
 	hostFile, err := os.Create(cpFullPath)
461
-	if err != nil {
462
-		c.Fatal(err)
463
-	}
449
+	c.Assert(err, checker.IsNil)
464 450
 	defer hostFile.Close()
465 451
 	defer os.RemoveAll(cpTestPathParent)
466 452
 
... ...
@@ -468,33 +357,26 @@ func (s *DockerSuite) TestCpSymlinkComponent(c *check.C) {
468 468
 
469 469
 	tmpdir, err := ioutil.TempDir("", "docker-integration")
470 470
 
471
-	if err != nil {
472
-		c.Fatal(err)
473
-	}
471
+	c.Assert(err, checker.IsNil)
474 472
 
475 473
 	tmpname := filepath.Join(tmpdir, cpTestName)
476 474
 	defer os.RemoveAll(tmpdir)
477 475
 
478 476
 	path := path.Join("/", "container_path", cpTestName)
479 477
 
480
-	dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
478
+	dockerCmd(c, "cp", containerID+":"+path, tmpdir)
481 479
 
482 480
 	file, _ := os.Open(tmpname)
483 481
 	defer file.Close()
484 482
 
485 483
 	test, err := ioutil.ReadAll(file)
486
-	if err != nil {
487
-		c.Fatal(err)
488
-	}
489
-
490
-	if string(test) == cpHostContents {
491
-		c.Errorf("output matched host file -- symlink path component can escape container rootfs")
492
-	}
484
+	c.Assert(err, checker.IsNil)
493 485
 
494
-	if string(test) != cpContainerContents {
495
-		c.Errorf("output doesn't match the input for symlink path component")
496
-	}
486
+	// output matched host file -- symlink path component can escape container rootfs
487
+	c.Assert(string(test), checker.Not(checker.Equals), cpHostContents)
497 488
 
489
+	// output doesn't match the input for symlink path component
490
+	c.Assert(string(test), checker.Equals, cpContainerContents)
498 491
 }
499 492
 
500 493
 // Check that cp with unprivileged user doesn't return any error
... ...
@@ -502,36 +384,25 @@ func (s *DockerSuite) TestCpUnprivilegedUser(c *check.C) {
502 502
 	testRequires(c, DaemonIsLinux)
503 503
 	testRequires(c, UnixCli) // uses chmod/su: not available on windows
504 504
 
505
-	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "touch "+cpTestName)
506
-	if exitCode != 0 {
507
-		c.Fatal("failed to create a container", out)
508
-	}
505
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "touch "+cpTestName)
509 506
 
510
-	cleanedContainerID := strings.TrimSpace(out)
507
+	containerID := strings.TrimSpace(out)
511 508
 
512
-	out, _ = dockerCmd(c, "wait", cleanedContainerID)
513
-	if strings.TrimSpace(out) != "0" {
514
-		c.Fatal("failed to set up container", out)
515
-	}
509
+	out, _ = dockerCmd(c, "wait", containerID)
510
+	// failed to set up container
511
+	c.Assert(strings.TrimSpace(out), checker.Equals, "0")
516 512
 
517 513
 	tmpdir, err := ioutil.TempDir("", "docker-integration")
518
-	if err != nil {
519
-		c.Fatal(err)
520
-	}
514
+	c.Assert(err, checker.IsNil)
521 515
 
522 516
 	defer os.RemoveAll(tmpdir)
523 517
 
524
-	if err = os.Chmod(tmpdir, 0777); err != nil {
525
-		c.Fatal(err)
526
-	}
518
+	c.Assert(os.Chmod(tmpdir, 0777), checker.IsNil)
527 519
 
528 520
 	path := cpTestName
529 521
 
530
-	_, _, err = runCommandWithOutput(exec.Command("su", "unprivilegeduser", "-c", dockerBinary+" cp "+cleanedContainerID+":"+path+" "+tmpdir))
531
-	if err != nil {
532
-		c.Fatalf("couldn't copy with unprivileged user: %s:%s %s", cleanedContainerID, path, err)
533
-	}
534
-
522
+	_, _, err = runCommandWithOutput(exec.Command("su", "unprivilegeduser", "-c", dockerBinary+" cp "+containerID+":"+path+" "+tmpdir))
523
+	c.Assert(err, checker.IsNil, check.Commentf("couldn't copy with unprivileged user: %s:%s", containerID, path))
535 524
 }
536 525
 
537 526
 func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {
... ...
@@ -539,53 +410,43 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {
539 539
 	testRequires(c, SameHostDaemon)
540 540
 
541 541
 	outDir, err := ioutil.TempDir("", "cp-test-special-files")
542
-	if err != nil {
543
-		c.Fatal(err)
544
-	}
542
+	c.Assert(err, checker.IsNil)
545 543
 	defer os.RemoveAll(outDir)
546 544
 
547
-	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "touch /foo")
548
-	if exitCode != 0 {
549
-		c.Fatal("failed to create a container", out)
550
-	}
545
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "touch /foo")
551 546
 
552
-	cleanedContainerID := strings.TrimSpace(out)
547
+	containerID := strings.TrimSpace(out)
553 548
 
554
-	out, _ = dockerCmd(c, "wait", cleanedContainerID)
555
-	if strings.TrimSpace(out) != "0" {
556
-		c.Fatal("failed to set up container", out)
557
-	}
549
+	out, _ = dockerCmd(c, "wait", containerID)
550
+	// failed to set up container
551
+	c.Assert(strings.TrimSpace(out), checker.Equals, "0")
558 552
 
559 553
 	// Copy actual /etc/resolv.conf
560
-	dockerCmd(c, "cp", cleanedContainerID+":/etc/resolv.conf", outDir)
554
+	dockerCmd(c, "cp", containerID+":/etc/resolv.conf", outDir)
561 555
 
562
-	expected, err := readContainerFile(cleanedContainerID, "resolv.conf")
556
+	expected, err := readContainerFile(containerID, "resolv.conf")
563 557
 	actual, err := ioutil.ReadFile(outDir + "/resolv.conf")
564 558
 
565
-	if !bytes.Equal(actual, expected) {
566
-		c.Fatalf("Expected copied file to be duplicate of the container resolvconf")
567
-	}
559
+	// Expected copied file to be duplicate of the container resolvconf
560
+	c.Assert(bytes.Equal(actual, expected), checker.True)
568 561
 
569 562
 	// Copy actual /etc/hosts
570
-	dockerCmd(c, "cp", cleanedContainerID+":/etc/hosts", outDir)
563
+	dockerCmd(c, "cp", containerID+":/etc/hosts", outDir)
571 564
 
572
-	expected, err = readContainerFile(cleanedContainerID, "hosts")
565
+	expected, err = readContainerFile(containerID, "hosts")
573 566
 	actual, err = ioutil.ReadFile(outDir + "/hosts")
574 567
 
575
-	if !bytes.Equal(actual, expected) {
576
-		c.Fatalf("Expected copied file to be duplicate of the container hosts")
577
-	}
568
+	// Expected copied file to be duplicate of the container hosts
569
+	c.Assert(bytes.Equal(actual, expected), checker.True)
578 570
 
579 571
 	// Copy actual /etc/resolv.conf
580
-	dockerCmd(c, "cp", cleanedContainerID+":/etc/hostname", outDir)
572
+	dockerCmd(c, "cp", containerID+":/etc/hostname", outDir)
581 573
 
582
-	expected, err = readContainerFile(cleanedContainerID, "hostname")
574
+	expected, err = readContainerFile(containerID, "hostname")
583 575
 	actual, err = ioutil.ReadFile(outDir + "/hostname")
584 576
 
585
-	if !bytes.Equal(actual, expected) {
586
-		c.Fatalf("Expected copied file to be duplicate of the container resolvconf")
587
-	}
588
-
577
+	// Expected copied file to be duplicate of the container resolvconf
578
+	c.Assert(bytes.Equal(actual, expected), checker.True)
589 579
 }
590 580
 
591 581
 func (s *DockerSuite) TestCpVolumePath(c *check.C) {
... ...
@@ -595,216 +456,148 @@ func (s *DockerSuite) TestCpVolumePath(c *check.C) {
595 595
 	testRequires(c, SameHostDaemon)
596 596
 
597 597
 	tmpDir, err := ioutil.TempDir("", "cp-test-volumepath")
598
-	if err != nil {
599
-		c.Fatal(err)
600
-	}
598
+	c.Assert(err, checker.IsNil)
601 599
 	defer os.RemoveAll(tmpDir)
602 600
 	outDir, err := ioutil.TempDir("", "cp-test-volumepath-out")
603
-	if err != nil {
604
-		c.Fatal(err)
605
-	}
601
+	c.Assert(err, checker.IsNil)
606 602
 	defer os.RemoveAll(outDir)
607 603
 	_, err = os.Create(tmpDir + "/test")
608
-	if err != nil {
609
-		c.Fatal(err)
610
-	}
604
+	c.Assert(err, checker.IsNil)
611 605
 
612
-	out, exitCode := dockerCmd(c, "run", "-d", "-v", "/foo", "-v", tmpDir+"/test:/test", "-v", tmpDir+":/baz", "busybox", "/bin/sh", "-c", "touch /foo/bar")
613
-	if exitCode != 0 {
614
-		c.Fatal("failed to create a container", out)
615
-	}
606
+	out, _ := dockerCmd(c, "run", "-d", "-v", "/foo", "-v", tmpDir+"/test:/test", "-v", tmpDir+":/baz", "busybox", "/bin/sh", "-c", "touch /foo/bar")
616 607
 
617
-	cleanedContainerID := strings.TrimSpace(out)
608
+	containerID := strings.TrimSpace(out)
618 609
 
619
-	out, _ = dockerCmd(c, "wait", cleanedContainerID)
620
-	if strings.TrimSpace(out) != "0" {
621
-		c.Fatal("failed to set up container", out)
622
-	}
610
+	out, _ = dockerCmd(c, "wait", containerID)
611
+	// failed to set up container
612
+	c.Assert(strings.TrimSpace(out), checker.Equals, "0")
623 613
 
624 614
 	// Copy actual volume path
625
-	dockerCmd(c, "cp", cleanedContainerID+":/foo", outDir)
615
+	dockerCmd(c, "cp", containerID+":/foo", outDir)
626 616
 
627 617
 	stat, err := os.Stat(outDir + "/foo")
628
-	if err != nil {
629
-		c.Fatal(err)
630
-	}
631
-	if !stat.IsDir() {
632
-		c.Fatal("expected copied content to be dir")
633
-	}
618
+	c.Assert(err, checker.IsNil)
619
+	// expected copied content to be dir
620
+	c.Assert(stat.IsDir(), checker.True)
634 621
 	stat, err = os.Stat(outDir + "/foo/bar")
635
-	if err != nil {
636
-		c.Fatal(err)
637
-	}
638
-	if stat.IsDir() {
639
-		c.Fatal("Expected file `bar` to be a file")
640
-	}
622
+	c.Assert(err, checker.IsNil)
623
+	// Expected file `bar` to be a file
624
+	c.Assert(stat.IsDir(), checker.False)
641 625
 
642 626
 	// Copy file nested in volume
643
-	dockerCmd(c, "cp", cleanedContainerID+":/foo/bar", outDir)
627
+	dockerCmd(c, "cp", containerID+":/foo/bar", outDir)
644 628
 
645 629
 	stat, err = os.Stat(outDir + "/bar")
646
-	if err != nil {
647
-		c.Fatal(err)
648
-	}
649
-	if stat.IsDir() {
650
-		c.Fatal("Expected file `bar` to be a file")
651
-	}
630
+	c.Assert(err, checker.IsNil)
631
+	// Expected file `bar` to be a file
632
+	c.Assert(stat.IsDir(), checker.False)
652 633
 
653 634
 	// Copy Bind-mounted dir
654
-	dockerCmd(c, "cp", cleanedContainerID+":/baz", outDir)
635
+	dockerCmd(c, "cp", containerID+":/baz", outDir)
655 636
 	stat, err = os.Stat(outDir + "/baz")
656
-	if err != nil {
657
-		c.Fatal(err)
658
-	}
659
-	if !stat.IsDir() {
660
-		c.Fatal("Expected `baz` to be a dir")
661
-	}
637
+	c.Assert(err, checker.IsNil)
638
+	// Expected `baz` to be a dir
639
+	c.Assert(stat.IsDir(), checker.True)
662 640
 
663 641
 	// Copy file nested in bind-mounted dir
664
-	dockerCmd(c, "cp", cleanedContainerID+":/baz/test", outDir)
642
+	dockerCmd(c, "cp", containerID+":/baz/test", outDir)
665 643
 	fb, err := ioutil.ReadFile(outDir + "/baz/test")
666
-	if err != nil {
667
-		c.Fatal(err)
668
-	}
644
+	c.Assert(err, checker.IsNil)
669 645
 	fb2, err := ioutil.ReadFile(tmpDir + "/test")
670
-	if err != nil {
671
-		c.Fatal(err)
672
-	}
673
-	if !bytes.Equal(fb, fb2) {
674
-		c.Fatalf("Expected copied file to be duplicate of bind-mounted file")
675
-	}
646
+	c.Assert(err, checker.IsNil)
647
+	// Expected copied file to be duplicate of bind-mounted file
648
+	c.Assert(bytes.Equal(fb, fb2), checker.True)
676 649
 
677 650
 	// Copy bind-mounted file
678
-	dockerCmd(c, "cp", cleanedContainerID+":/test", outDir)
651
+	dockerCmd(c, "cp", containerID+":/test", outDir)
679 652
 	fb, err = ioutil.ReadFile(outDir + "/test")
680
-	if err != nil {
681
-		c.Fatal(err)
682
-	}
653
+	c.Assert(err, checker.IsNil)
683 654
 	fb2, err = ioutil.ReadFile(tmpDir + "/test")
684
-	if err != nil {
685
-		c.Fatal(err)
686
-	}
687
-	if !bytes.Equal(fb, fb2) {
688
-		c.Fatalf("Expected copied file to be duplicate of bind-mounted file")
689
-	}
690
-
655
+	c.Assert(err, checker.IsNil)
656
+	// Expected copied file to be duplicate of bind-mounted file
657
+	c.Assert(bytes.Equal(fb, fb2), checker.True)
691 658
 }
692 659
 
693 660
 func (s *DockerSuite) TestCpToDot(c *check.C) {
694 661
 	testRequires(c, DaemonIsLinux)
695
-	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test")
696
-	if exitCode != 0 {
697
-		c.Fatal("failed to create a container", out)
698
-	}
662
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test")
699 663
 
700
-	cleanedContainerID := strings.TrimSpace(out)
664
+	containerID := strings.TrimSpace(out)
701 665
 
702
-	out, _ = dockerCmd(c, "wait", cleanedContainerID)
703
-	if strings.TrimSpace(out) != "0" {
704
-		c.Fatal("failed to set up container", out)
705
-	}
666
+	out, _ = dockerCmd(c, "wait", containerID)
667
+	// failed to set up container
668
+	c.Assert(strings.TrimSpace(out), checker.Equals, "0")
706 669
 
707 670
 	tmpdir, err := ioutil.TempDir("", "docker-integration")
708
-	if err != nil {
709
-		c.Fatal(err)
710
-	}
671
+	c.Assert(err, checker.IsNil)
711 672
 	defer os.RemoveAll(tmpdir)
712 673
 	cwd, err := os.Getwd()
713
-	if err != nil {
714
-		c.Fatal(err)
715
-	}
674
+	c.Assert(err, checker.IsNil)
716 675
 	defer os.Chdir(cwd)
717
-	if err := os.Chdir(tmpdir); err != nil {
718
-		c.Fatal(err)
719
-	}
720
-	dockerCmd(c, "cp", cleanedContainerID+":/test", ".")
676
+	c.Assert(os.Chdir(tmpdir), checker.IsNil)
677
+	dockerCmd(c, "cp", containerID+":/test", ".")
721 678
 	content, err := ioutil.ReadFile("./test")
722
-	if string(content) != "lololol\n" {
723
-		c.Fatalf("Wrong content in copied file %q, should be %q", content, "lololol\n")
724
-	}
679
+	c.Assert(string(content), checker.Equals, "lololol\n")
725 680
 }
726 681
 
727 682
 func (s *DockerSuite) TestCpToStdout(c *check.C) {
728 683
 	testRequires(c, DaemonIsLinux)
729
-	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test")
730
-	if exitCode != 0 {
731
-		c.Fatalf("failed to create a container:%s\n", out)
732
-	}
684
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test")
733 685
 
734
-	cID := strings.TrimSpace(out)
686
+	containerID := strings.TrimSpace(out)
735 687
 
736
-	out, _ = dockerCmd(c, "wait", cID)
737
-	if strings.TrimSpace(out) != "0" {
738
-		c.Fatalf("failed to set up container:%s\n", out)
739
-	}
688
+	out, _ = dockerCmd(c, "wait", containerID)
689
+	// failed to set up container
690
+	c.Assert(strings.TrimSpace(out), checker.Equals, "0")
740 691
 
741 692
 	out, _, err := runCommandPipelineWithOutput(
742
-		exec.Command(dockerBinary, "cp", cID+":/test", "-"),
693
+		exec.Command(dockerBinary, "cp", containerID+":/test", "-"),
743 694
 		exec.Command("tar", "-vtf", "-"))
744 695
 
745
-	if err != nil {
746
-		c.Fatalf("Failed to run commands: %s", err)
747
-	}
696
+	c.Assert(err, checker.IsNil)
748 697
 
749
-	if !strings.Contains(out, "test") || !strings.Contains(out, "-rw") {
750
-		c.Fatalf("Missing file from tar TOC:\n%s", out)
751
-	}
698
+	c.Assert(out, checker.Contains, "test")
699
+	c.Assert(out, checker.Contains, "-rw")
752 700
 }
753 701
 
754 702
 func (s *DockerSuite) TestCpNameHasColon(c *check.C) {
755 703
 	testRequires(c, SameHostDaemon)
756 704
 
757
-	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /te:s:t")
758
-	if exitCode != 0 {
759
-		c.Fatal("failed to create a container", out)
760
-	}
705
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /te:s:t")
761 706
 
762
-	cleanedContainerID := strings.TrimSpace(out)
707
+	containerID := strings.TrimSpace(out)
763 708
 
764
-	out, _ = dockerCmd(c, "wait", cleanedContainerID)
765
-	if strings.TrimSpace(out) != "0" {
766
-		c.Fatal("failed to set up container", out)
767
-	}
709
+	out, _ = dockerCmd(c, "wait", containerID)
710
+	// failed to set up container
711
+	c.Assert(strings.TrimSpace(out), checker.Equals, "0")
768 712
 
769 713
 	tmpdir, err := ioutil.TempDir("", "docker-integration")
770
-	if err != nil {
771
-		c.Fatal(err)
772
-	}
714
+	c.Assert(err, checker.IsNil)
773 715
 	defer os.RemoveAll(tmpdir)
774
-	dockerCmd(c, "cp", cleanedContainerID+":/te:s:t", tmpdir)
716
+	dockerCmd(c, "cp", containerID+":/te:s:t", tmpdir)
775 717
 	content, err := ioutil.ReadFile(tmpdir + "/te:s:t")
776
-	if string(content) != "lololol\n" {
777
-		c.Fatalf("Wrong content in copied file %q, should be %q", content, "lololol\n")
778
-	}
718
+	c.Assert(string(content), checker.Equals, "lololol\n")
779 719
 }
780 720
 
781 721
 func (s *DockerSuite) TestCopyAndRestart(c *check.C) {
782 722
 	testRequires(c, DaemonIsLinux)
783 723
 	expectedMsg := "hello"
784 724
 	out, _ := dockerCmd(c, "run", "-d", "busybox", "echo", expectedMsg)
785
-	id := strings.TrimSpace(string(out))
725
+	containerID := strings.TrimSpace(out)
786 726
 
787
-	out, _ = dockerCmd(c, "wait", id)
788
-
789
-	status := strings.TrimSpace(out)
790
-	if status != "0" {
791
-		c.Fatalf("container exited with status %s", status)
792
-	}
727
+	out, _ = dockerCmd(c, "wait", containerID)
728
+	// failed to set up container
729
+	c.Assert(strings.TrimSpace(out), checker.Equals, "0")
793 730
 
794 731
 	tmpDir, err := ioutil.TempDir("", "test-docker-restart-after-copy-")
795
-	if err != nil {
796
-		c.Fatalf("unable to make temporary directory: %s", err)
797
-	}
732
+	c.Assert(err, checker.IsNil)
798 733
 	defer os.RemoveAll(tmpDir)
799 734
 
800
-	dockerCmd(c, "cp", fmt.Sprintf("%s:/etc/group", id), tmpDir)
735
+	dockerCmd(c, "cp", fmt.Sprintf("%s:/etc/group", containerID), tmpDir)
801 736
 
802
-	out, _ = dockerCmd(c, "start", "-a", id)
737
+	out, _ = dockerCmd(c, "start", "-a", containerID)
803 738
 
804
-	msg := strings.TrimSpace(out)
805
-	if msg != expectedMsg {
806
-		c.Fatalf("expected %q but got %q", expectedMsg, msg)
807
-	}
739
+	c.Assert(strings.TrimSpace(out), checker.Equals, expectedMsg)
808 740
 }
809 741
 
810 742
 func (s *DockerSuite) TestCopyCreatedContainer(c *check.C) {
... ...
@@ -812,9 +605,7 @@ func (s *DockerSuite) TestCopyCreatedContainer(c *check.C) {
812 812
 	dockerCmd(c, "create", "--name", "test_cp", "-v", "/test", "busybox")
813 813
 
814 814
 	tmpDir, err := ioutil.TempDir("", "test")
815
-	if err != nil {
816
-		c.Fatalf("unable to make temporary directory: %s", err)
817
-	}
815
+	c.Assert(err, checker.IsNil)
818 816
 	defer os.RemoveAll(tmpDir)
819 817
 	dockerCmd(c, "cp", "test_cp:/bin/sh", tmpDir)
820 818
 }
... ...
@@ -3,6 +3,7 @@ package main
3 3
 import (
4 4
 	"os"
5 5
 
6
+	"github.com/docker/docker/pkg/integration/checker"
6 7
 	"github.com/go-check/check"
7 8
 )
8 9
 
... ...
@@ -23,31 +24,25 @@ import (
23 23
 // Test for error when SRC does not exist.
24 24
 func (s *DockerSuite) TestCpToErrSrcNotExists(c *check.C) {
25 25
 	testRequires(c, DaemonIsLinux)
26
-	cID := makeTestContainer(c, testContainerOptions{})
27
-	defer deleteContainer(cID)
26
+	containerID := makeTestContainer(c, testContainerOptions{})
28 27
 
29 28
 	tmpDir := getTestDir(c, "test-cp-to-err-src-not-exists")
30 29
 	defer os.RemoveAll(tmpDir)
31 30
 
32 31
 	srcPath := cpPath(tmpDir, "file1")
33
-	dstPath := containerCpPath(cID, "file1")
32
+	dstPath := containerCpPath(containerID, "file1")
34 33
 
35 34
 	err := runDockerCp(c, srcPath, dstPath)
36
-	if err == nil {
37
-		c.Fatal("expected IsNotExist error, but got nil instead")
38
-	}
35
+	c.Assert(err, checker.NotNil)
39 36
 
40
-	if !isCpNotExist(err) {
41
-		c.Fatalf("expected IsNotExist error, but got %T: %s", err, err)
42
-	}
37
+	c.Assert(isCpNotExist(err), checker.True, check.Commentf("expected IsNotExist error, but got %T: %s", err, err))
43 38
 }
44 39
 
45 40
 // Test for error when SRC ends in a trailing
46 41
 // path separator but it exists as a file.
47 42
 func (s *DockerSuite) TestCpToErrSrcNotDir(c *check.C) {
48 43
 	testRequires(c, DaemonIsLinux)
49
-	cID := makeTestContainer(c, testContainerOptions{})
50
-	defer deleteContainer(cID)
44
+	containerID := makeTestContainer(c, testContainerOptions{})
51 45
 
52 46
 	tmpDir := getTestDir(c, "test-cp-to-err-src-not-dir")
53 47
 	defer os.RemoveAll(tmpDir)
... ...
@@ -55,24 +50,19 @@ func (s *DockerSuite) TestCpToErrSrcNotDir(c *check.C) {
55 55
 	makeTestContentInDir(c, tmpDir)
56 56
 
57 57
 	srcPath := cpPathTrailingSep(tmpDir, "file1")
58
-	dstPath := containerCpPath(cID, "testDir")
58
+	dstPath := containerCpPath(containerID, "testDir")
59 59
 
60 60
 	err := runDockerCp(c, srcPath, dstPath)
61
-	if err == nil {
62
-		c.Fatal("expected IsNotDir error, but got nil instead")
63
-	}
61
+	c.Assert(err, checker.NotNil)
64 62
 
65
-	if !isCpNotDir(err) {
66
-		c.Fatalf("expected IsNotDir error, but got %T: %s", err, err)
67
-	}
63
+	c.Assert(isCpNotDir(err), checker.True, check.Commentf("expected IsNotDir error, but got %T: %s", err, err))
68 64
 }
69 65
 
70 66
 // Test for error when SRC is a valid file or directory,
71 67
 // bu the DST parent directory does not exist.
72 68
 func (s *DockerSuite) TestCpToErrDstParentNotExists(c *check.C) {
73 69
 	testRequires(c, DaemonIsLinux)
74
-	cID := makeTestContainer(c, testContainerOptions{addContent: true})
75
-	defer deleteContainer(cID)
70
+	containerID := makeTestContainer(c, testContainerOptions{addContent: true})
76 71
 
77 72
 	tmpDir := getTestDir(c, "test-cp-to-err-dst-parent-not-exists")
78 73
 	defer os.RemoveAll(tmpDir)
... ...
@@ -81,27 +71,19 @@ func (s *DockerSuite) TestCpToErrDstParentNotExists(c *check.C) {
81 81
 
82 82
 	// Try with a file source.
83 83
 	srcPath := cpPath(tmpDir, "file1")
84
-	dstPath := containerCpPath(cID, "/notExists", "file1")
84
+	dstPath := containerCpPath(containerID, "/notExists", "file1")
85 85
 
86 86
 	err := runDockerCp(c, srcPath, dstPath)
87
-	if err == nil {
88
-		c.Fatal("expected IsNotExist error, but got nil instead")
89
-	}
87
+	c.Assert(err, checker.NotNil)
90 88
 
91
-	if !isCpNotExist(err) {
92
-		c.Fatalf("expected IsNotExist error, but got %T: %s", err, err)
93
-	}
89
+	c.Assert(isCpNotExist(err), checker.True, check.Commentf("expected IsNotExist error, but got %T: %s", err, err))
94 90
 
95 91
 	// Try with a directory source.
96 92
 	srcPath = cpPath(tmpDir, "dir1")
97 93
 
98
-	if err := runDockerCp(c, srcPath, dstPath); err == nil {
99
-		c.Fatal("expected IsNotExist error, but got nil instead")
100
-	}
94
+	c.Assert(err, checker.NotNil)
101 95
 
102
-	if !isCpNotExist(err) {
103
-		c.Fatalf("expected IsNotExist error, but got %T: %s", err, err)
104
-	}
96
+	c.Assert(isCpNotExist(err), checker.True, check.Commentf("expected IsNotExist error, but got %T: %s", err, err))
105 97
 }
106 98
 
107 99
 // Test for error when DST ends in a trailing path separator but exists as a
... ...
@@ -109,8 +91,7 @@ func (s *DockerSuite) TestCpToErrDstParentNotExists(c *check.C) {
109 109
 // non-directory and cannot overwrite an existing
110 110
 func (s *DockerSuite) TestCpToErrDstNotDir(c *check.C) {
111 111
 	testRequires(c, DaemonIsLinux)
112
-	cID := makeTestContainer(c, testContainerOptions{addContent: true})
113
-	defer deleteContainer(cID)
112
+	containerID := makeTestContainer(c, testContainerOptions{addContent: true})
114 113
 
115 114
 	tmpDir := getTestDir(c, "test-cp-to-err-dst-not-dir")
116 115
 	defer os.RemoveAll(tmpDir)
... ...
@@ -119,19 +100,15 @@ func (s *DockerSuite) TestCpToErrDstNotDir(c *check.C) {
119 119
 
120 120
 	// Try with a file source.
121 121
 	srcPath := cpPath(tmpDir, "dir1/file1-1")
122
-	dstPath := containerCpPathTrailingSep(cID, "file1")
122
+	dstPath := containerCpPathTrailingSep(containerID, "file1")
123 123
 
124 124
 	// The client should encounter an error trying to stat the destination
125 125
 	// and then be unable to copy since the destination is asserted to be a
126 126
 	// directory but does not exist.
127 127
 	err := runDockerCp(c, srcPath, dstPath)
128
-	if err == nil {
129
-		c.Fatal("expected DirNotExist error, but got nil instead")
130
-	}
128
+	c.Assert(err, checker.NotNil)
131 129
 
132
-	if !isCpDirNotExist(err) {
133
-		c.Fatalf("expected DirNotExist error, but got %T: %s", err, err)
134
-	}
130
+	c.Assert(isCpDirNotExist(err), checker.True, check.Commentf("expected DirNotExist error, but got %T: %s", err, err))
135 131
 
136 132
 	// Try with a directory source.
137 133
 	srcPath = cpPath(tmpDir, "dir1")
... ...
@@ -141,13 +118,9 @@ func (s *DockerSuite) TestCpToErrDstNotDir(c *check.C) {
141 141
 	// name in the source archive, but this directory would overwrite the
142 142
 	// existing file with the same name.
143 143
 	err = runDockerCp(c, srcPath, dstPath)
144
-	if err == nil {
145
-		c.Fatal("expected CannotOverwriteNonDirWithDir error, but got nil instead")
146
-	}
144
+	c.Assert(err, checker.NotNil)
147 145
 
148
-	if !isCannotOverwriteNonDirWithDir(err) {
149
-		c.Fatalf("expected CannotOverwriteNonDirWithDir error, but got %T: %s", err, err)
150
-	}
146
+	c.Assert(isCannotOverwriteNonDirWithDir(err), checker.True, check.Commentf("expected CannotOverwriteNonDirWithDir error, but got %T: %s", err, err))
151 147
 }
152 148
 
153 149
 // Check that copying from a local path to a symlink in a container copies to
... ...
@@ -163,106 +136,75 @@ func (s *DockerSuite) TestCpToSymlinkDestination(c *check.C) {
163 163
 
164 164
 	makeTestContentInDir(c, testVol)
165 165
 
166
-	cID := makeTestContainer(c, testContainerOptions{
166
+	containerID := makeTestContainer(c, testContainerOptions{
167 167
 		volumes: defaultVolumes(testVol), // Our bind mount is at /vol2
168 168
 	})
169
-	defer deleteContainer(cID)
170 169
 
171 170
 	// First, copy a local file to a symlink to a file in the container. This
172 171
 	// should overwrite the symlink target contents with the source contents.
173 172
 	srcPath := cpPath(testVol, "file2")
174
-	dstPath := containerCpPath(cID, "/vol2/symlinkToFile1")
173
+	dstPath := containerCpPath(containerID, "/vol2/symlinkToFile1")
175 174
 
176
-	if err := runDockerCp(c, srcPath, dstPath); err != nil {
177
-		c.Fatalf("unexpected error %T: %s", err, err)
178
-	}
175
+	c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
179 176
 
180 177
 	// The symlink should not have been modified.
181
-	if err := symlinkTargetEquals(c, cpPath(testVol, "symlinkToFile1"), "file1"); err != nil {
182
-		c.Fatal(err)
183
-	}
178
+	c.Assert(symlinkTargetEquals(c, cpPath(testVol, "symlinkToFile1"), "file1"), checker.IsNil)
184 179
 
185 180
 	// The file should have the contents of "file2" now.
186
-	if err := fileContentEquals(c, cpPath(testVol, "file1"), "file2\n"); err != nil {
187
-		c.Fatal(err)
188
-	}
181
+	c.Assert(fileContentEquals(c, cpPath(testVol, "file1"), "file2\n"), checker.IsNil)
189 182
 
190 183
 	// Next, copy a local file to a symlink to a directory in the container.
191 184
 	// This should copy the file into the symlink target directory.
192
-	dstPath = containerCpPath(cID, "/vol2/symlinkToDir1")
185
+	dstPath = containerCpPath(containerID, "/vol2/symlinkToDir1")
193 186
 
194
-	if err := runDockerCp(c, srcPath, dstPath); err != nil {
195
-		c.Fatalf("unexpected error %T: %s", err, err)
196
-	}
187
+	c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
197 188
 
198 189
 	// The symlink should not have been modified.
199
-	if err := symlinkTargetEquals(c, cpPath(testVol, "symlinkToDir1"), "dir1"); err != nil {
200
-		c.Fatal(err)
201
-	}
190
+	c.Assert(symlinkTargetEquals(c, cpPath(testVol, "symlinkToDir1"), "dir1"), checker.IsNil)
202 191
 
203 192
 	// The file should have the contents of "file2" now.
204
-	if err := fileContentEquals(c, cpPath(testVol, "file2"), "file2\n"); err != nil {
205
-		c.Fatal(err)
206
-	}
193
+	c.Assert(fileContentEquals(c, cpPath(testVol, "file2"), "file2\n"), checker.IsNil)
207 194
 
208 195
 	// Next, copy a file to a symlink to a file that does not exist (a broken
209 196
 	// symlink) in the container. This should create the target file with the
210 197
 	// contents of the source file.
211
-	dstPath = containerCpPath(cID, "/vol2/brokenSymlinkToFileX")
198
+	dstPath = containerCpPath(containerID, "/vol2/brokenSymlinkToFileX")
212 199
 
213
-	if err := runDockerCp(c, srcPath, dstPath); err != nil {
214
-		c.Fatalf("unexpected error %T: %s", err, err)
215
-	}
200
+	c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
216 201
 
217 202
 	// The symlink should not have been modified.
218
-	if err := symlinkTargetEquals(c, cpPath(testVol, "brokenSymlinkToFileX"), "fileX"); err != nil {
219
-		c.Fatal(err)
220
-	}
203
+	c.Assert(symlinkTargetEquals(c, cpPath(testVol, "brokenSymlinkToFileX"), "fileX"), checker.IsNil)
221 204
 
222 205
 	// The file should have the contents of "file2" now.
223
-	if err := fileContentEquals(c, cpPath(testVol, "fileX"), "file2\n"); err != nil {
224
-		c.Fatal(err)
225
-	}
206
+	c.Assert(fileContentEquals(c, cpPath(testVol, "fileX"), "file2\n"), checker.IsNil)
226 207
 
227 208
 	// Next, copy a local directory to a symlink to a directory in the
228 209
 	// container. This should copy the directory into the symlink target
229 210
 	// directory and not modify the symlink.
230 211
 	srcPath = cpPath(testVol, "/dir2")
231
-	dstPath = containerCpPath(cID, "/vol2/symlinkToDir1")
212
+	dstPath = containerCpPath(containerID, "/vol2/symlinkToDir1")
232 213
 
233
-	if err := runDockerCp(c, srcPath, dstPath); err != nil {
234
-		c.Fatalf("unexpected error %T: %s", err, err)
235
-	}
214
+	c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
236 215
 
237 216
 	// The symlink should not have been modified.
238
-	if err := symlinkTargetEquals(c, cpPath(testVol, "symlinkToDir1"), "dir1"); err != nil {
239
-		c.Fatal(err)
240
-	}
217
+	c.Assert(symlinkTargetEquals(c, cpPath(testVol, "symlinkToDir1"), "dir1"), checker.IsNil)
241 218
 
242 219
 	// The directory should now contain a copy of "dir2".
243
-	if err := fileContentEquals(c, cpPath(testVol, "dir1/dir2/file2-1"), "file2-1\n"); err != nil {
244
-		c.Fatal(err)
245
-	}
220
+	c.Assert(fileContentEquals(c, cpPath(testVol, "dir1/dir2/file2-1"), "file2-1\n"), checker.IsNil)
246 221
 
247 222
 	// Next, copy a local directory to a symlink to a local directory that does
248 223
 	// not exist (a broken symlink) in the container. This should create the
249 224
 	// target as a directory with the contents of the source directory. It
250 225
 	// should not modify the symlink.
251
-	dstPath = containerCpPath(cID, "/vol2/brokenSymlinkToDirX")
226
+	dstPath = containerCpPath(containerID, "/vol2/brokenSymlinkToDirX")
252 227
 
253
-	if err := runDockerCp(c, srcPath, dstPath); err != nil {
254
-		c.Fatalf("unexpected error %T: %s", err, err)
255
-	}
228
+	c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
256 229
 
257 230
 	// The symlink should not have been modified.
258
-	if err := symlinkTargetEquals(c, cpPath(testVol, "brokenSymlinkToDirX"), "dirX"); err != nil {
259
-		c.Fatal(err)
260
-	}
231
+	c.Assert(symlinkTargetEquals(c, cpPath(testVol, "brokenSymlinkToDirX"), "dirX"), checker.IsNil)
261 232
 
262 233
 	// The "dirX" directory should now be a copy of "dir2".
263
-	if err := fileContentEquals(c, cpPath(testVol, "dirX/file2-1"), "file2-1\n"); err != nil {
264
-		c.Fatal(err)
265
-	}
234
+	c.Assert(fileContentEquals(c, cpPath(testVol, "dirX/file2-1"), "file2-1\n"), checker.IsNil)
266 235
 }
267 236
 
268 237
 // Possibilities are reduced to the remaining 10 cases:
... ...
@@ -286,10 +228,9 @@ func (s *DockerSuite) TestCpToSymlinkDestination(c *check.C) {
286 286
 //    contents of the source file into it.
287 287
 func (s *DockerSuite) TestCpToCaseA(c *check.C) {
288 288
 	testRequires(c, DaemonIsLinux)
289
-	cID := makeTestContainer(c, testContainerOptions{
289
+	containerID := makeTestContainer(c, testContainerOptions{
290 290
 		workDir: "/root", command: makeCatFileCommand("itWorks.txt"),
291 291
 	})
292
-	defer deleteContainer(cID)
293 292
 
294 293
 	tmpDir := getTestDir(c, "test-cp-to-case-a")
295 294
 	defer os.RemoveAll(tmpDir)
... ...
@@ -297,15 +238,11 @@ func (s *DockerSuite) TestCpToCaseA(c *check.C) {
297 297
 	makeTestContentInDir(c, tmpDir)
298 298
 
299 299
 	srcPath := cpPath(tmpDir, "file1")
300
-	dstPath := containerCpPath(cID, "/root/itWorks.txt")
300
+	dstPath := containerCpPath(containerID, "/root/itWorks.txt")
301 301
 
302
-	if err := runDockerCp(c, srcPath, dstPath); err != nil {
303
-		c.Fatalf("unexpected error %T: %s", err, err)
304
-	}
302
+	c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
305 303
 
306
-	if err := containerStartOutputEquals(c, cID, "file1\n"); err != nil {
307
-		c.Fatal(err)
308
-	}
304
+	c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
309 305
 }
310 306
 
311 307
 // B. SRC specifies a file and DST (with trailing path separator) doesn't
... ...
@@ -313,10 +250,9 @@ func (s *DockerSuite) TestCpToCaseA(c *check.C) {
313 313
 //    create a directory when copying a single file.
314 314
 func (s *DockerSuite) TestCpToCaseB(c *check.C) {
315 315
 	testRequires(c, DaemonIsLinux)
316
-	cID := makeTestContainer(c, testContainerOptions{
316
+	containerID := makeTestContainer(c, testContainerOptions{
317 317
 		command: makeCatFileCommand("testDir/file1"),
318 318
 	})
319
-	defer deleteContainer(cID)
320 319
 
321 320
 	tmpDir := getTestDir(c, "test-cp-to-case-b")
322 321
 	defer os.RemoveAll(tmpDir)
... ...
@@ -324,27 +260,22 @@ func (s *DockerSuite) TestCpToCaseB(c *check.C) {
324 324
 	makeTestContentInDir(c, tmpDir)
325 325
 
326 326
 	srcPath := cpPath(tmpDir, "file1")
327
-	dstDir := containerCpPathTrailingSep(cID, "testDir")
327
+	dstDir := containerCpPathTrailingSep(containerID, "testDir")
328 328
 
329 329
 	err := runDockerCp(c, srcPath, dstDir)
330
-	if err == nil {
331
-		c.Fatal("expected DirNotExists error, but got nil instead")
332
-	}
330
+	c.Assert(err, checker.NotNil)
333 331
 
334
-	if !isCpDirNotExist(err) {
335
-		c.Fatalf("expected DirNotExists error, but got %T: %s", err, err)
336
-	}
332
+	c.Assert(isCpDirNotExist(err), checker.True, check.Commentf("expected DirNotExists error, but got %T: %s", err, err))
337 333
 }
338 334
 
339 335
 // C. SRC specifies a file and DST exists as a file. This should overwrite
340 336
 //    the file at DST with the contents of the source file.
341 337
 func (s *DockerSuite) TestCpToCaseC(c *check.C) {
342 338
 	testRequires(c, DaemonIsLinux)
343
-	cID := makeTestContainer(c, testContainerOptions{
339
+	containerID := makeTestContainer(c, testContainerOptions{
344 340
 		addContent: true, workDir: "/root",
345 341
 		command: makeCatFileCommand("file2"),
346 342
 	})
347
-	defer deleteContainer(cID)
348 343
 
349 344
 	tmpDir := getTestDir(c, "test-cp-to-case-c")
350 345
 	defer os.RemoveAll(tmpDir)
... ...
@@ -352,21 +283,15 @@ func (s *DockerSuite) TestCpToCaseC(c *check.C) {
352 352
 	makeTestContentInDir(c, tmpDir)
353 353
 
354 354
 	srcPath := cpPath(tmpDir, "file1")
355
-	dstPath := containerCpPath(cID, "/root/file2")
355
+	dstPath := containerCpPath(containerID, "/root/file2")
356 356
 
357 357
 	// Ensure the container's file starts with the original content.
358
-	if err := containerStartOutputEquals(c, cID, "file2\n"); err != nil {
359
-		c.Fatal(err)
360
-	}
358
+	c.Assert(containerStartOutputEquals(c, containerID, "file2\n"), checker.IsNil)
361 359
 
362
-	if err := runDockerCp(c, srcPath, dstPath); err != nil {
363
-		c.Fatalf("unexpected error %T: %s", err, err)
364
-	}
360
+	c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
365 361
 
366 362
 	// Should now contain file1's contents.
367
-	if err := containerStartOutputEquals(c, cID, "file1\n"); err != nil {
368
-		c.Fatal(err)
369
-	}
363
+	c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
370 364
 }
371 365
 
372 366
 // D. SRC specifies a file and DST exists as a directory. This should place
... ...
@@ -374,11 +299,10 @@ func (s *DockerSuite) TestCpToCaseC(c *check.C) {
374 374
 //    this works whether DST has a trailing path separator or not.
375 375
 func (s *DockerSuite) TestCpToCaseD(c *check.C) {
376 376
 	testRequires(c, DaemonIsLinux)
377
-	cID := makeTestContainer(c, testContainerOptions{
377
+	containerID := makeTestContainer(c, testContainerOptions{
378 378
 		addContent: true,
379 379
 		command:    makeCatFileCommand("/dir1/file1"),
380 380
 	})
381
-	defer deleteContainer(cID)
382 381
 
383 382
 	tmpDir := getTestDir(c, "test-cp-to-case-d")
384 383
 	defer os.RemoveAll(tmpDir)
... ...
@@ -386,46 +310,33 @@ func (s *DockerSuite) TestCpToCaseD(c *check.C) {
386 386
 	makeTestContentInDir(c, tmpDir)
387 387
 
388 388
 	srcPath := cpPath(tmpDir, "file1")
389
-	dstDir := containerCpPath(cID, "dir1")
389
+	dstDir := containerCpPath(containerID, "dir1")
390 390
 
391 391
 	// Ensure that dstPath doesn't exist.
392
-	if err := containerStartOutputEquals(c, cID, ""); err != nil {
393
-		c.Fatal(err)
394
-	}
392
+	c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
395 393
 
396
-	if err := runDockerCp(c, srcPath, dstDir); err != nil {
397
-		c.Fatalf("unexpected error %T: %s", err, err)
398
-	}
394
+	c.Assert(runDockerCp(c, srcPath, dstDir), checker.IsNil)
399 395
 
400 396
 	// Should now contain file1's contents.
401
-	if err := containerStartOutputEquals(c, cID, "file1\n"); err != nil {
402
-		c.Fatal(err)
403
-	}
397
+	c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
404 398
 
405 399
 	// Now try again but using a trailing path separator for dstDir.
406 400
 
407 401
 	// Make new destination container.
408
-	cID = makeTestContainer(c, testContainerOptions{
402
+	containerID = makeTestContainer(c, testContainerOptions{
409 403
 		addContent: true,
410 404
 		command:    makeCatFileCommand("/dir1/file1"),
411 405
 	})
412
-	defer deleteContainer(cID)
413 406
 
414
-	dstDir = containerCpPathTrailingSep(cID, "dir1")
407
+	dstDir = containerCpPathTrailingSep(containerID, "dir1")
415 408
 
416 409
 	// Ensure that dstPath doesn't exist.
417
-	if err := containerStartOutputEquals(c, cID, ""); err != nil {
418
-		c.Fatal(err)
419
-	}
410
+	c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
420 411
 
421
-	if err := runDockerCp(c, srcPath, dstDir); err != nil {
422
-		c.Fatalf("unexpected error %T: %s", err, err)
423
-	}
412
+	c.Assert(runDockerCp(c, srcPath, dstDir), checker.IsNil)
424 413
 
425 414
 	// Should now contain file1's contents.
426
-	if err := containerStartOutputEquals(c, cID, "file1\n"); err != nil {
427
-		c.Fatal(err)
428
-	}
415
+	c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
429 416
 }
430 417
 
431 418
 // E. SRC specifies a directory and DST does not exist. This should create a
... ...
@@ -434,10 +345,9 @@ func (s *DockerSuite) TestCpToCaseD(c *check.C) {
434 434
 //    not.
435 435
 func (s *DockerSuite) TestCpToCaseE(c *check.C) {
436 436
 	testRequires(c, DaemonIsLinux)
437
-	cID := makeTestContainer(c, testContainerOptions{
437
+	containerID := makeTestContainer(c, testContainerOptions{
438 438
 		command: makeCatFileCommand("/testDir/file1-1"),
439 439
 	})
440
-	defer deleteContainer(cID)
441 440
 
442 441
 	tmpDir := getTestDir(c, "test-cp-to-case-e")
443 442
 	defer os.RemoveAll(tmpDir)
... ...
@@ -445,46 +355,35 @@ func (s *DockerSuite) TestCpToCaseE(c *check.C) {
445 445
 	makeTestContentInDir(c, tmpDir)
446 446
 
447 447
 	srcDir := cpPath(tmpDir, "dir1")
448
-	dstDir := containerCpPath(cID, "testDir")
448
+	dstDir := containerCpPath(containerID, "testDir")
449 449
 
450
-	if err := runDockerCp(c, srcDir, dstDir); err != nil {
451
-		c.Fatalf("unexpected error %T: %s", err, err)
452
-	}
450
+	c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
453 451
 
454 452
 	// Should now contain file1-1's contents.
455
-	if err := containerStartOutputEquals(c, cID, "file1-1\n"); err != nil {
456
-		c.Fatal(err)
457
-	}
453
+	c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
458 454
 
459 455
 	// Now try again but using a trailing path separator for dstDir.
460 456
 
461 457
 	// Make new destination container.
462
-	cID = makeTestContainer(c, testContainerOptions{
458
+	containerID = makeTestContainer(c, testContainerOptions{
463 459
 		command: makeCatFileCommand("/testDir/file1-1"),
464 460
 	})
465
-	defer deleteContainer(cID)
466 461
 
467
-	dstDir = containerCpPathTrailingSep(cID, "testDir")
462
+	dstDir = containerCpPathTrailingSep(containerID, "testDir")
468 463
 
469
-	err := runDockerCp(c, srcDir, dstDir)
470
-	if err != nil {
471
-		c.Fatalf("unexpected error %T: %s", err, err)
472
-	}
464
+	c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
473 465
 
474 466
 	// Should now contain file1-1's contents.
475
-	if err := containerStartOutputEquals(c, cID, "file1-1\n"); err != nil {
476
-		c.Fatal(err)
477
-	}
467
+	c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
478 468
 }
479 469
 
480 470
 // F. SRC specifies a directory and DST exists as a file. This should cause an
481 471
 //    error as it is not possible to overwrite a file with a directory.
482 472
 func (s *DockerSuite) TestCpToCaseF(c *check.C) {
483 473
 	testRequires(c, DaemonIsLinux)
484
-	cID := makeTestContainer(c, testContainerOptions{
474
+	containerID := makeTestContainer(c, testContainerOptions{
485 475
 		addContent: true, workDir: "/root",
486 476
 	})
487
-	defer deleteContainer(cID)
488 477
 
489 478
 	tmpDir := getTestDir(c, "test-cp-to-case-f")
490 479
 	defer os.RemoveAll(tmpDir)
... ...
@@ -492,16 +391,12 @@ func (s *DockerSuite) TestCpToCaseF(c *check.C) {
492 492
 	makeTestContentInDir(c, tmpDir)
493 493
 
494 494
 	srcDir := cpPath(tmpDir, "dir1")
495
-	dstFile := containerCpPath(cID, "/root/file1")
495
+	dstFile := containerCpPath(containerID, "/root/file1")
496 496
 
497 497
 	err := runDockerCp(c, srcDir, dstFile)
498
-	if err == nil {
499
-		c.Fatal("expected ErrCannotCopyDir error, but got nil instead")
500
-	}
498
+	c.Assert(err, checker.NotNil)
501 499
 
502
-	if !isCpCannotCopyDir(err) {
503
-		c.Fatalf("expected ErrCannotCopyDir error, but got %T: %s", err, err)
504
-	}
500
+	c.Assert(isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
505 501
 }
506 502
 
507 503
 // G. SRC specifies a directory and DST exists as a directory. This should copy
... ...
@@ -509,11 +404,10 @@ func (s *DockerSuite) TestCpToCaseF(c *check.C) {
509 509
 //    works whether DST has a trailing path separator or not.
510 510
 func (s *DockerSuite) TestCpToCaseG(c *check.C) {
511 511
 	testRequires(c, DaemonIsLinux)
512
-	cID := makeTestContainer(c, testContainerOptions{
512
+	containerID := makeTestContainer(c, testContainerOptions{
513 513
 		addContent: true, workDir: "/root",
514 514
 		command: makeCatFileCommand("dir2/dir1/file1-1"),
515 515
 	})
516
-	defer deleteContainer(cID)
517 516
 
518 517
 	tmpDir := getTestDir(c, "test-cp-to-case-g")
519 518
 	defer os.RemoveAll(tmpDir)
... ...
@@ -521,46 +415,33 @@ func (s *DockerSuite) TestCpToCaseG(c *check.C) {
521 521
 	makeTestContentInDir(c, tmpDir)
522 522
 
523 523
 	srcDir := cpPath(tmpDir, "dir1")
524
-	dstDir := containerCpPath(cID, "/root/dir2")
524
+	dstDir := containerCpPath(containerID, "/root/dir2")
525 525
 
526 526
 	// Ensure that dstPath doesn't exist.
527
-	if err := containerStartOutputEquals(c, cID, ""); err != nil {
528
-		c.Fatal(err)
529
-	}
527
+	c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
530 528
 
531
-	if err := runDockerCp(c, srcDir, dstDir); err != nil {
532
-		c.Fatalf("unexpected error %T: %s", err, err)
533
-	}
529
+	c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
534 530
 
535 531
 	// Should now contain file1-1's contents.
536
-	if err := containerStartOutputEquals(c, cID, "file1-1\n"); err != nil {
537
-		c.Fatal(err)
538
-	}
532
+	c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
539 533
 
540 534
 	// Now try again but using a trailing path separator for dstDir.
541 535
 
542 536
 	// Make new destination container.
543
-	cID = makeTestContainer(c, testContainerOptions{
537
+	containerID = makeTestContainer(c, testContainerOptions{
544 538
 		addContent: true,
545 539
 		command:    makeCatFileCommand("/dir2/dir1/file1-1"),
546 540
 	})
547
-	defer deleteContainer(cID)
548 541
 
549
-	dstDir = containerCpPathTrailingSep(cID, "/dir2")
542
+	dstDir = containerCpPathTrailingSep(containerID, "/dir2")
550 543
 
551 544
 	// Ensure that dstPath doesn't exist.
552
-	if err := containerStartOutputEquals(c, cID, ""); err != nil {
553
-		c.Fatal(err)
554
-	}
545
+	c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
555 546
 
556
-	if err := runDockerCp(c, srcDir, dstDir); err != nil {
557
-		c.Fatalf("unexpected error %T: %s", err, err)
558
-	}
547
+	c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
559 548
 
560 549
 	// Should now contain file1-1's contents.
561
-	if err := containerStartOutputEquals(c, cID, "file1-1\n"); err != nil {
562
-		c.Fatal(err)
563
-	}
550
+	c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
564 551
 }
565 552
 
566 553
 // H. SRC specifies a directory's contents only and DST does not exist. This
... ...
@@ -569,10 +450,9 @@ func (s *DockerSuite) TestCpToCaseG(c *check.C) {
569 569
 //    this works whether DST has a trailing path separator or not.
570 570
 func (s *DockerSuite) TestCpToCaseH(c *check.C) {
571 571
 	testRequires(c, DaemonIsLinux)
572
-	cID := makeTestContainer(c, testContainerOptions{
572
+	containerID := makeTestContainer(c, testContainerOptions{
573 573
 		command: makeCatFileCommand("/testDir/file1-1"),
574 574
 	})
575
-	defer deleteContainer(cID)
576 575
 
577 576
 	tmpDir := getTestDir(c, "test-cp-to-case-h")
578 577
 	defer os.RemoveAll(tmpDir)
... ...
@@ -580,35 +460,26 @@ func (s *DockerSuite) TestCpToCaseH(c *check.C) {
580 580
 	makeTestContentInDir(c, tmpDir)
581 581
 
582 582
 	srcDir := cpPathTrailingSep(tmpDir, "dir1") + "."
583
-	dstDir := containerCpPath(cID, "testDir")
583
+	dstDir := containerCpPath(containerID, "testDir")
584 584
 
585
-	if err := runDockerCp(c, srcDir, dstDir); err != nil {
586
-		c.Fatalf("unexpected error %T: %s", err, err)
587
-	}
585
+	c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
588 586
 
589 587
 	// Should now contain file1-1's contents.
590
-	if err := containerStartOutputEquals(c, cID, "file1-1\n"); err != nil {
591
-		c.Fatal(err)
592
-	}
588
+	c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
593 589
 
594 590
 	// Now try again but using a trailing path separator for dstDir.
595 591
 
596 592
 	// Make new destination container.
597
-	cID = makeTestContainer(c, testContainerOptions{
593
+	containerID = makeTestContainer(c, testContainerOptions{
598 594
 		command: makeCatFileCommand("/testDir/file1-1"),
599 595
 	})
600
-	defer deleteContainer(cID)
601 596
 
602
-	dstDir = containerCpPathTrailingSep(cID, "testDir")
597
+	dstDir = containerCpPathTrailingSep(containerID, "testDir")
603 598
 
604
-	if err := runDockerCp(c, srcDir, dstDir); err != nil {
605
-		c.Fatalf("unexpected error %T: %s", err, err)
606
-	}
599
+	c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
607 600
 
608 601
 	// Should now contain file1-1's contents.
609
-	if err := containerStartOutputEquals(c, cID, "file1-1\n"); err != nil {
610
-		c.Fatal(err)
611
-	}
602
+	c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
612 603
 }
613 604
 
614 605
 // I. SRC specifies a directory's contents only and DST exists as a file. This
... ...
@@ -616,10 +487,9 @@ func (s *DockerSuite) TestCpToCaseH(c *check.C) {
616 616
 //    directory.
617 617
 func (s *DockerSuite) TestCpToCaseI(c *check.C) {
618 618
 	testRequires(c, DaemonIsLinux)
619
-	cID := makeTestContainer(c, testContainerOptions{
619
+	containerID := makeTestContainer(c, testContainerOptions{
620 620
 		addContent: true, workDir: "/root",
621 621
 	})
622
-	defer deleteContainer(cID)
623 622
 
624 623
 	tmpDir := getTestDir(c, "test-cp-to-case-i")
625 624
 	defer os.RemoveAll(tmpDir)
... ...
@@ -627,16 +497,12 @@ func (s *DockerSuite) TestCpToCaseI(c *check.C) {
627 627
 	makeTestContentInDir(c, tmpDir)
628 628
 
629 629
 	srcDir := cpPathTrailingSep(tmpDir, "dir1") + "."
630
-	dstFile := containerCpPath(cID, "/root/file1")
630
+	dstFile := containerCpPath(containerID, "/root/file1")
631 631
 
632 632
 	err := runDockerCp(c, srcDir, dstFile)
633
-	if err == nil {
634
-		c.Fatal("expected ErrCannotCopyDir error, but got nil instead")
635
-	}
633
+	c.Assert(err, checker.NotNil)
636 634
 
637
-	if !isCpCannotCopyDir(err) {
638
-		c.Fatalf("expected ErrCannotCopyDir error, but got %T: %s", err, err)
639
-	}
635
+	c.Assert(isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
640 636
 }
641 637
 
642 638
 // J. SRC specifies a directory's contents only and DST exists as a directory.
... ...
@@ -645,11 +511,10 @@ func (s *DockerSuite) TestCpToCaseI(c *check.C) {
645 645
 //    trailing path separator or not.
646 646
 func (s *DockerSuite) TestCpToCaseJ(c *check.C) {
647 647
 	testRequires(c, DaemonIsLinux)
648
-	cID := makeTestContainer(c, testContainerOptions{
648
+	containerID := makeTestContainer(c, testContainerOptions{
649 649
 		addContent: true, workDir: "/root",
650 650
 		command: makeCatFileCommand("/dir2/file1-1"),
651 651
 	})
652
-	defer deleteContainer(cID)
653 652
 
654 653
 	tmpDir := getTestDir(c, "test-cp-to-case-j")
655 654
 	defer os.RemoveAll(tmpDir)
... ...
@@ -657,45 +522,32 @@ func (s *DockerSuite) TestCpToCaseJ(c *check.C) {
657 657
 	makeTestContentInDir(c, tmpDir)
658 658
 
659 659
 	srcDir := cpPathTrailingSep(tmpDir, "dir1") + "."
660
-	dstDir := containerCpPath(cID, "/dir2")
660
+	dstDir := containerCpPath(containerID, "/dir2")
661 661
 
662 662
 	// Ensure that dstPath doesn't exist.
663
-	if err := containerStartOutputEquals(c, cID, ""); err != nil {
664
-		c.Fatal(err)
665
-	}
663
+	c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
666 664
 
667
-	if err := runDockerCp(c, srcDir, dstDir); err != nil {
668
-		c.Fatalf("unexpected error %T: %s", err, err)
669
-	}
665
+	c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
670 666
 
671 667
 	// Should now contain file1-1's contents.
672
-	if err := containerStartOutputEquals(c, cID, "file1-1\n"); err != nil {
673
-		c.Fatal(err)
674
-	}
668
+	c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
675 669
 
676 670
 	// Now try again but using a trailing path separator for dstDir.
677 671
 
678 672
 	// Make new destination container.
679
-	cID = makeTestContainer(c, testContainerOptions{
673
+	containerID = makeTestContainer(c, testContainerOptions{
680 674
 		command: makeCatFileCommand("/dir2/file1-1"),
681 675
 	})
682
-	defer deleteContainer(cID)
683 676
 
684
-	dstDir = containerCpPathTrailingSep(cID, "/dir2")
677
+	dstDir = containerCpPathTrailingSep(containerID, "/dir2")
685 678
 
686 679
 	// Ensure that dstPath doesn't exist.
687
-	if err := containerStartOutputEquals(c, cID, ""); err != nil {
688
-		c.Fatal(err)
689
-	}
680
+	c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
690 681
 
691
-	if err := runDockerCp(c, srcDir, dstDir); err != nil {
692
-		c.Fatalf("unexpected error %T: %s", err, err)
693
-	}
682
+	c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
694 683
 
695 684
 	// Should now contain file1-1's contents.
696
-	if err := containerStartOutputEquals(c, cID, "file1-1\n"); err != nil {
697
-		c.Fatal(err)
698
-	}
685
+	c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
699 686
 }
700 687
 
701 688
 // The `docker cp` command should also ensure that you cannot
... ...
@@ -708,28 +560,21 @@ func (s *DockerSuite) TestCpToErrReadOnlyRootfs(c *check.C) {
708 708
 
709 709
 	makeTestContentInDir(c, tmpDir)
710 710
 
711
-	cID := makeTestContainer(c, testContainerOptions{
711
+	containerID := makeTestContainer(c, testContainerOptions{
712 712
 		readOnly: true, workDir: "/root",
713 713
 		command: makeCatFileCommand("shouldNotExist"),
714 714
 	})
715
-	defer deleteContainer(cID)
716 715
 
717 716
 	srcPath := cpPath(tmpDir, "file1")
718
-	dstPath := containerCpPath(cID, "/root/shouldNotExist")
717
+	dstPath := containerCpPath(containerID, "/root/shouldNotExist")
719 718
 
720 719
 	err := runDockerCp(c, srcPath, dstPath)
721
-	if err == nil {
722
-		c.Fatal("expected ErrContainerRootfsReadonly error, but got nil instead")
723
-	}
720
+	c.Assert(err, checker.NotNil)
724 721
 
725
-	if !isCpCannotCopyReadOnly(err) {
726
-		c.Fatalf("expected ErrContainerRootfsReadonly error, but got %T: %s", err, err)
727
-	}
722
+	c.Assert(isCpCannotCopyReadOnly(err), checker.True, check.Commentf("expected ErrContainerRootfsReadonly error, but got %T: %s", err, err))
728 723
 
729 724
 	// Ensure that dstPath doesn't exist.
730
-	if err := containerStartOutputEquals(c, cID, ""); err != nil {
731
-		c.Fatal(err)
732
-	}
725
+	c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
733 726
 }
734 727
 
735 728
 // The `docker cp` command should also ensure that you
... ...
@@ -742,26 +587,19 @@ func (s *DockerSuite) TestCpToErrReadOnlyVolume(c *check.C) {
742 742
 
743 743
 	makeTestContentInDir(c, tmpDir)
744 744
 
745
-	cID := makeTestContainer(c, testContainerOptions{
745
+	containerID := makeTestContainer(c, testContainerOptions{
746 746
 		volumes: defaultVolumes(tmpDir), workDir: "/root",
747 747
 		command: makeCatFileCommand("/vol_ro/shouldNotExist"),
748 748
 	})
749
-	defer deleteContainer(cID)
750 749
 
751 750
 	srcPath := cpPath(tmpDir, "file1")
752
-	dstPath := containerCpPath(cID, "/vol_ro/shouldNotExist")
751
+	dstPath := containerCpPath(containerID, "/vol_ro/shouldNotExist")
753 752
 
754 753
 	err := runDockerCp(c, srcPath, dstPath)
755
-	if err == nil {
756
-		c.Fatal("expected ErrVolumeReadonly error, but got nil instead")
757
-	}
754
+	c.Assert(err, checker.NotNil)
758 755
 
759
-	if !isCpCannotCopyReadOnly(err) {
760
-		c.Fatalf("expected ErrVolumeReadonly error, but got %T: %s", err, err)
761
-	}
756
+	c.Assert(isCpCannotCopyReadOnly(err), checker.True, check.Commentf("expected ErrVolumeReadonly error, but got %T: %s", err, err))
762 757
 
763 758
 	// Ensure that dstPath doesn't exist.
764
-	if err := containerStartOutputEquals(c, cID, ""); err != nil {
765
-		c.Fatal(err)
766
-	}
759
+	c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
767 760
 }
... ...
@@ -10,6 +10,7 @@ import (
10 10
 	"strings"
11 11
 
12 12
 	"github.com/docker/docker/pkg/archive"
13
+	"github.com/docker/docker/pkg/integration/checker"
13 14
 	"github.com/go-check/check"
14 15
 )
15 16
 
... ...
@@ -90,17 +91,11 @@ func makeTestContentInDir(c *check.C, dir string) {
90 90
 		path := filepath.Join(dir, filepath.FromSlash(fd.path))
91 91
 		switch fd.filetype {
92 92
 		case ftRegular:
93
-			if err := ioutil.WriteFile(path, []byte(fd.contents+"\n"), os.FileMode(0666)); err != nil {
94
-				c.Fatal(err)
95
-			}
93
+			c.Assert(ioutil.WriteFile(path, []byte(fd.contents+"\n"), os.FileMode(0666)), checker.IsNil)
96 94
 		case ftDir:
97
-			if err := os.Mkdir(path, os.FileMode(0777)); err != nil {
98
-				c.Fatal(err)
99
-			}
95
+			c.Assert(os.Mkdir(path, os.FileMode(0777)), checker.IsNil)
100 96
 		case ftSymlink:
101
-			if err := os.Symlink(fd.contents, path); err != nil {
102
-				c.Fatal(err)
103
-			}
97
+			c.Assert(os.Symlink(fd.contents, path), checker.IsNil)
104 98
 		}
105 99
 	}
106 100
 }
... ...
@@ -143,25 +138,17 @@ func makeTestContainer(c *check.C, options testContainerOptions) (containerID st
143 143
 
144 144
 	args = append(args, "busybox", "/bin/sh", "-c", options.command)
145 145
 
146
-	out, status := dockerCmd(c, args...)
147
-	if status != 0 {
148
-		c.Fatalf("failed to run container, status %d: %s", status, out)
149
-	}
146
+	out, _ := dockerCmd(c, args...)
150 147
 
151 148
 	containerID = strings.TrimSpace(out)
152 149
 
153
-	out, status = dockerCmd(c, "wait", containerID)
154
-	if status != 0 {
155
-		c.Fatalf("failed to wait for test container container, status %d: %s", status, out)
156
-	}
150
+	out, _ = dockerCmd(c, "wait", containerID)
157 151
 
158
-	if exitCode := strings.TrimSpace(out); exitCode != "0" {
159
-		logs, status := dockerCmd(c, "logs", containerID)
160
-		if status != 0 {
161
-			logs = "UNABLE TO GET LOGS"
162
-		}
163
-		c.Fatalf("failed to make test container, exit code (%s): %s", exitCode, logs)
152
+	exitCode := strings.TrimSpace(out)
153
+	if exitCode != "0" {
154
+		out, _ = dockerCmd(c, "logs", containerID)
164 155
 	}
156
+	c.Assert(exitCode, checker.Equals, "0", check.Commentf("failed to make test container: %s", out))
165 157
 
166 158
 	return
167 159
 }
... ...
@@ -204,10 +191,10 @@ func runDockerCp(c *check.C, src, dst string) (err error) {
204 204
 	return
205 205
 }
206 206
 
207
-func startContainerGetOutput(c *check.C, cID string) (out string, err error) {
208
-	c.Logf("running `docker start -a %s`", cID)
207
+func startContainerGetOutput(c *check.C, containerID string) (out string, err error) {
208
+	c.Logf("running `docker start -a %s`", containerID)
209 209
 
210
-	args := []string{"start", "-a", cID}
210
+	args := []string{"start", "-a", containerID}
211 211
 
212 212
 	out, _, err = runCommandWithOutput(exec.Command(dockerBinary, args...))
213 213
 	if err != nil {
... ...
@@ -220,9 +207,9 @@ func startContainerGetOutput(c *check.C, cID string) (out string, err error) {
220 220
 func getTestDir(c *check.C, label string) (tmpDir string) {
221 221
 	var err error
222 222
 
223
-	if tmpDir, err = ioutil.TempDir("", label); err != nil {
224
-		c.Fatalf("unable to make temporary directory: %s", err)
225
-	}
223
+	tmpDir, err = ioutil.TempDir("", label)
224
+	// unable to make temporary directory
225
+	c.Assert(err, checker.IsNil)
226 226
 
227 227
 	return
228 228
 }
... ...
@@ -276,22 +263,22 @@ func symlinkTargetEquals(c *check.C, symlink, expectedTarget string) (err error)
276 276
 
277 277
 	actualTarget, err := os.Readlink(symlink)
278 278
 	if err != nil {
279
-		return err
279
+		return
280 280
 	}
281 281
 
282 282
 	if actualTarget != expectedTarget {
283
-		return fmt.Errorf("symlink target points to %q not %q", actualTarget, expectedTarget)
283
+		err = fmt.Errorf("symlink target points to %q not %q", actualTarget, expectedTarget)
284 284
 	}
285 285
 
286
-	return nil
286
+	return
287 287
 }
288 288
 
289
-func containerStartOutputEquals(c *check.C, cID, contents string) (err error) {
290
-	c.Logf("checking that container %q start output contains %q\n", cID, contents)
289
+func containerStartOutputEquals(c *check.C, containerID, contents string) (err error) {
290
+	c.Logf("checking that container %q start output contains %q\n", containerID, contents)
291 291
 
292
-	out, err := startContainerGetOutput(c, cID)
292
+	out, err := startContainerGetOutput(c, containerID)
293 293
 	if err != nil {
294
-		return err
294
+		return
295 295
 	}
296 296
 
297 297
 	if out != contents {