Skip to content

Commit

Permalink
move logic to isCompatibleWith
Browse files Browse the repository at this point in the history
  • Loading branch information
eddumelendez committed Dec 3, 2022
1 parent 3daf95d commit 2fef0b0
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions core/src/main/java/org/testcontainers/utility/DockerImageName.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.testcontainers.utility.Versioning.Sha256Versioning;
import org.testcontainers.utility.Versioning.TagVersioning;

import java.util.Arrays;
import java.util.regex.Pattern;

@EqualsAndHashCode(exclude = { "rawName", "compatibleSubstituteFor" })
Expand Down Expand Up @@ -235,7 +234,14 @@ public DockerImageName asCompatibleSubstituteFor(DockerImageName otherImageName)
*/
public boolean isCompatibleWith(DockerImageName other) {
// is this image already the same or equivalent?
if (other.equals(this)) {
String finalImageName;
if (this.repository.startsWith(LIBRARY_PREFIX)) {
finalImageName = this.repository;
} else {
finalImageName = LIBRARY_PREFIX + this.repository;
}
DockerImageName imageWithLibraryPrefix = DockerImageName.parse(finalImageName);
if (other.equals(this) || imageWithLibraryPrefix.equals(this)) {
return true;
}

Expand All @@ -261,21 +267,13 @@ public void assertCompatibleWith(DockerImageName... anyOthers) {
throw new IllegalArgumentException("anyOthers parameter must be non-empty");
}

DockerImageName[] dockerImageNames = Arrays.copyOf(anyOthers, anyOthers.length + 1);
if (this.repository.startsWith(LIBRARY_PREFIX)) {
dockerImageNames[dockerImageNames.length - 1] = DockerImageName.parse(this.repository);
} else {
String imageWithLibraryPrefix = LIBRARY_PREFIX + this.repository;
dockerImageNames[dockerImageNames.length - 1] = DockerImageName.parse(imageWithLibraryPrefix);
}

for (DockerImageName anyOther : dockerImageNames) {
for (DockerImageName anyOther : anyOthers) {
if (this.isCompatibleWith(anyOther)) {
return;
}
}

final DockerImageName exampleOther = dockerImageNames[0];
final DockerImageName exampleOther = anyOthers[0];

throw new IllegalStateException(
String.format(
Expand Down

0 comments on commit 2fef0b0

Please sign in to comment.