Browse code

integration-cli/build: don't panic

A lack of check in the test code can lead to a panic due to
`len(ids)` being `0`.

Avoid the panic by adding appropriate checks. Note `Assert()` should be
used rather than `Check()` as if it fails we should not proceed with the
test.

Originally found in https://github.com/moby/moby/pull/38404.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>

Kir Kolyshkin authored on 2018/12/21 10:39:29
Showing 1 changed files
... ...
@@ -298,7 +298,7 @@ func (s *DockerSuite) TestBuildOnBuildCache(c *check.C) {
298 298
 
299 299
 		out, err := request.ReadBody(body)
300 300
 		assert.NilError(c, err)
301
-		assert.Check(c, is.Contains(string(out), "Successfully built"))
301
+		assert.Assert(c, is.Contains(string(out), "Successfully built"))
302 302
 		return out
303 303
 	}
304 304
 
... ...
@@ -313,7 +313,7 @@ func (s *DockerSuite) TestBuildOnBuildCache(c *check.C) {
313 313
 	out := build(dockerfile)
314 314
 
315 315
 	imageIDs := getImageIDsFromBuild(c, out)
316
-	assert.Check(c, is.Len(imageIDs, 2))
316
+	assert.Assert(c, is.Len(imageIDs, 2))
317 317
 	parentID, childID := imageIDs[0], imageIDs[1]
318 318
 
319 319
 	client := testEnv.APIClient()
... ...
@@ -457,8 +457,10 @@ COPY file /file`
457 457
 
458 458
 		out, err := request.ReadBody(body)
459 459
 		assert.NilError(c, err)
460
+		assert.Assert(c, is.Contains(string(out), "Successfully built"))
460 461
 
461 462
 		ids := getImageIDsFromBuild(c, out)
463
+		assert.Assert(c, is.Len(ids, 1))
462 464
 		return ids[len(ids)-1]
463 465
 	}
464 466
 
... ...
@@ -496,8 +498,10 @@ ADD file /file`
496 496
 
497 497
 		out, err := request.ReadBody(body)
498 498
 		assert.NilError(c, err)
499
+		assert.Assert(c, is.Contains(string(out), "Successfully built"))
499 500
 
500 501
 		ids := getImageIDsFromBuild(c, out)
502
+		assert.Assert(c, is.Len(ids, 1))
501 503
 		return ids[len(ids)-1]
502 504
 	}
503 505