Skip to content

Commit

Permalink
Fix testImageLabels
Browse files Browse the repository at this point in the history
Don't bother counting the number of new images built with labels.
Just check that the ones we built exist. There are too many edge cases
to take care of since images are left behind from previous builds. These
edge cases mess up the count.
  • Loading branch information
davidxia committed Mar 8, 2016
1 parent d31ac29 commit 34f7c93
Showing 1 changed file with 2 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2216,13 +2216,6 @@ public void testImageLabels() throws DockerException,
final String dockerDirectory =
Resources.getResource("dockerDirectoryWithImageLabels").getPath();

// Check if any images already exist with the labels we will use
final List<Image> preexistingTestImages = sut.listImages(
ListImagesParam.withLabel("name", "testtesttest"));
final int numPreexistingTestImages = preexistingTestImages.size();
// Make a list of just the image IDs
final List<String> preexistingTestImageIds = imagesToShortIds(preexistingTestImages);

// Create test images
final String barDir = (new File(dockerDirectory, "barDir")).toString();
final String barName = randomName();
Expand All @@ -2237,21 +2230,8 @@ public void testImageLabels() throws DockerException,
ListImagesParam.withLabel("name"));
final List<String> nameIds = imagesToShortIds(nameImages);

// Find how many of the newly created images already existed.
// Building the same Dockerfile multiple times results in one image locally with the same ID.
// So subtract this number from the expected number of image IDs below.
// Otherwise, running this test multiple times fails because it'll expect two more IDs.
int numOverlappingTestImageIds = 0;
for (final String nameId : nameIds) {
for (final String preNameId : preexistingTestImageIds) {
if (preNameId.contains(nameId)) {
numOverlappingTestImageIds++;
}
}
}

assertThat(nameIds.size(), equalTo(2 + numPreexistingTestImages - numOverlappingTestImageIds));
assertThat(nameIds, containsInAnyOrder(barId, bazId));
assertTrue(nameIds.contains(barId));
assertTrue(nameIds.contains(bazId));

// Check that the first image is listed when we filter with a "foo=bar" label
final List<Image> barImages = sut.listImages(
Expand Down

0 comments on commit 34f7c93

Please sign in to comment.