Skip to content

Commit 7e7ff2a

Browse files
committed
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 moby#38404. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 92b34ec commit 7e7ff2a

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

integration-cli/docker_api_build_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ func (s *DockerSuite) TestBuildOnBuildCache(c *check.C) {
298298

299299
out, err := request.ReadBody(body)
300300
assert.NilError(c, err)
301-
assert.Check(c, is.Contains(string(out), "Successfully built"))
301+
assert.Assert(c, is.Contains(string(out), "Successfully built"))
302302
return out
303303
}
304304

@@ -313,7 +313,7 @@ func (s *DockerSuite) TestBuildOnBuildCache(c *check.C) {
313313
out := build(dockerfile)
314314

315315
imageIDs := getImageIDsFromBuild(c, out)
316-
assert.Check(c, is.Len(imageIDs, 2))
316+
assert.Assert(c, is.Len(imageIDs, 2))
317317
parentID, childID := imageIDs[0], imageIDs[1]
318318

319319
client := testEnv.APIClient()
@@ -457,8 +457,10 @@ COPY file /file`
457457

458458
out, err := request.ReadBody(body)
459459
assert.NilError(c, err)
460+
assert.Assert(c, is.Contains(string(out), "Successfully built"))
460461

461462
ids := getImageIDsFromBuild(c, out)
463+
assert.Assert(c, is.Len(ids, 1))
462464
return ids[len(ids)-1]
463465
}
464466

@@ -496,8 +498,10 @@ ADD file /file`
496498

497499
out, err := request.ReadBody(body)
498500
assert.NilError(c, err)
501+
assert.Assert(c, is.Contains(string(out), "Successfully built"))
499502

500503
ids := getImageIDsFromBuild(c, out)
504+
assert.Assert(c, is.Len(ids, 1))
501505
return ids[len(ids)-1]
502506
}
503507

0 commit comments

Comments
 (0)