diff --git a/core/src/main/java/org/testcontainers/utility/DockerImageName.java b/core/src/main/java/org/testcontainers/utility/DockerImageName.java index 9fca02aad6f..e3a35855bf8 100644 --- a/core/src/main/java/org/testcontainers/utility/DockerImageName.java +++ b/core/src/main/java/org/testcontainers/utility/DockerImageName.java @@ -26,6 +26,8 @@ public final class DockerImageName { private static final Pattern REPO_NAME = Pattern.compile(REPO_NAME_PART + "(/" + REPO_NAME_PART + ")*"); + private static final String LIBRARY_PREFIX = "library/"; + private final String rawName; @With @@ -231,8 +233,15 @@ public DockerImageName asCompatibleSubstituteFor(DockerImageName otherImageName) * @return whether this image has declared compatibility. */ public boolean isCompatibleWith(DockerImageName other) { - // is this image already the same or equivalent? - if (other.equals(this)) { + // Make sure we always compare against a version of the image name containing the LIBRARY_PREFIX + 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; } diff --git a/core/src/test/java/org/testcontainers/utility/DockerImageNameCompatibilityTest.java b/core/src/test/java/org/testcontainers/utility/DockerImageNameCompatibilityTest.java index 0bb1b3f75ca..dd17981111f 100644 --- a/core/src/test/java/org/testcontainers/utility/DockerImageNameCompatibilityTest.java +++ b/core/src/test/java/org/testcontainers/utility/DockerImageNameCompatibilityTest.java @@ -91,6 +91,12 @@ public void testAssertMethodAcceptsCompatible() { subject.assertCompatibleWith(DockerImageName.parse("bar")); } + @Test + public void testAssertMethodAcceptsCompatibleLibraryPrefix() { + DockerImageName subject = DockerImageName.parse("library/foo"); + subject.assertCompatibleWith(DockerImageName.parse("foo")); + } + @Test public void testAssertMethodRejectsIncompatible() { DockerImageName subject = DockerImageName.parse("foo");