testcontainers / testcontainers/testcontainers-java
[Enhancement]: Expose `compatibleSubstituteFor()` through API
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 1.9k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 9
Description
Module
Core
Proposal
I would like to allow unversioned images like wiremock/wiremock:test if and only if compatibleSubstituteFor is explicitly set by the users. By default, IMHO the validation should fail, because we cannot compare against the minimum required version.
At the moment it is not possible, because there is no getter method for compatibleSubstituteFor
Sample code
public WireMockContainer(DockerImageName dockerImage) {
super(dockerImage);
dockerImage.assertCompatibleWith(new DockerImageName(OFFICIAL_IMAGE_NAME));
// Verify the minimum version for the official image
final ComparableVersion version = new ComparableVersion(dockerImage.getVersionPart());
if (!version.isSemanticVersion()) { // Accept only images when compatibility is declared explicitly
// TODO: We cannot extract compatibleSubstituteFor from Testcontainers API
} else {
boolean isLessThanBaseVersion = version.isLessThan(WIREMOCK_2_MINIMUM_SUPPORTED_VERSION);
if (OFFICIAL_IMAGE_NAME.equals(dockerImage.getUnversionedPart()) && isLessThanBaseVersion) {
throw new IllegalArgumentException("For the official image, the WireMock version must be >= " + WIREMOCK_2_MINIMUM_SUPPORTED_VERSION);
}
}
// ...
Sample Test
@Test
@Disabled("Requires https://github.com/testcontainers/testcontainers-java/issues/7305")
public void shouldFailForUnversionedImage() {
IllegalStateException ex = Assertions.assertThrows(IllegalStateException.class, () -> {
WireMockContainer container = new WireMockContainer(
new DockerImageName(WireMockContainer.OFFICIAL_IMAGE_NAME, "test"));
});
assertThat(ex.getMessage())
.as("Wrong exception message")
.contains("Failed to verify that image")
.contains("is a compatible substitute for '" + WireMockContainer.OFFICIAL_IMAGE_NAME + "'");
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the DockerImageName and compatibleSubstituteFor/assertCompatibleWith API paths shown in the issue, then locate their related tests. Expose the explicitly configured compatible substitute and enable the disabled WireMockContainer test once it can verify the expected failure message.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100