Skip to content

Commit

Permalink
fix(docker): correct is image used by others check (#1491)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeDombo authored Jun 20, 2023
1 parent bc5ee63 commit 8fa0f36
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,14 @@ public boolean ifImageUsedByOther(ComponentStore componentStore) throws PackageL
for (String compVersion : localVersions) {
try {
ComponentIdentifier identifier = new ComponentIdentifier(compName, new Semver(compVersion));
// this.identifier is to be deleted identifier
// this.identifier is to be deleted identifier. Skip checking ourselves.
if (identifier.equals(this.identifier)) {
ComponentRecipe recipe = componentStore.getPackageRecipe(identifier);
if (recipe.getArtifacts().stream().anyMatch(
i -> i.getArtifactUri().equals(artifact.getArtifactUri()))) {
return true;
}
continue;
}
ComponentRecipe recipe = componentStore.getPackageRecipe(identifier);
if (recipe.getArtifacts().stream().anyMatch(
i -> i.getArtifactUri().equals(artifact.getArtifactUri()))) {
return true;
}
} catch (SemverException e) {
logger.atWarn().kv("identifier", identifier.getName()).kv("compVersion", compVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
Expand Down Expand Up @@ -527,16 +528,24 @@ void GIVEN_a_artifact_with_private_ecr_image_THEN_check_if_image_used_by_others(
allVersions.put("com.example.HelloWorld", versions);
when(componentStore.listAvailableComponentVersions()).thenReturn(allVersions);

ComponentRecipe recipe = new ComponentRecipe(RecipeFormatVersion.JAN_25_2020, "com.example.HelloWorld",
new Semver("1.0.0", Semver.SemverType.NPM), "", "", null, new HashMap<String, Object>() {{
put("LIFECYCLE_RUN_KEY", "java -jar {artifacts:path}/test.jar -x arg");
}}, Collections.emptyList(), Collections.emptyMap(), null);
when(componentStore.getPackageRecipe(any())).thenReturn(recipe);

assertFalse(downloader.ifImageUsedByOther(componentStore));

Set<String> versions_test = new HashSet<>();
versions_test.add(TEST_COMPONENT_ID.getVersion().getValue());
versions_test.add("2.0.0");
allVersions.put(TEST_COMPONENT_ID.getName(), versions_test);
ComponentRecipe recipe = new ComponentRecipe(RecipeFormatVersion.JAN_25_2020, "com.example.HelloWorld",
recipe = new ComponentRecipe(RecipeFormatVersion.JAN_25_2020, TEST_COMPONENT_ID.getName(),
new Semver("2.0.0", Semver.SemverType.NPM), "", "", null, new HashMap<String, Object>() {{
put("LIFECYCLE_RUN_KEY", "java -jar {artifacts:path}/test.jar -x arg");
}}, new ArrayList<ComponentArtifact>() {{ add(ComponentArtifact.builder().artifactUri(artifactUri).build());}}, Collections.emptyMap(), null);
when(componentStore.getPackageRecipe(any())).thenReturn(recipe);
when(componentStore.getPackageRecipe(eq(new ComponentIdentifier(TEST_COMPONENT_ID.getName(),
new Semver("2.0.0", Semver.SemverType.NPM))))).thenReturn(recipe);

assertTrue(downloader.ifImageUsedByOther(componentStore));
}
Expand Down

0 comments on commit 8fa0f36

Please sign in to comment.