Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override ChainedImageNameSubstitutor toString #7522

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ protected String getDescription() {
configuredInstance.getDescription()
);
}

@Override
public String toString() {
return getDescription();
}
}

private static class NoopImageNameSubstitutor extends ImageNameSubstitutor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mockito;
import org.testcontainers.containers.GenericContainer;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.eq;

public class ImageNameSubstitutorTest {
Expand Down Expand Up @@ -64,4 +66,19 @@ public void testWorksWithoutConfiguredImplementation() {
.as("the image has been substituted by default then configured implementations")
.isEqualTo("substituted-image:latest");
}

@Test
public void testImageNameSubstitutorToString() {
Mockito
.doReturn(FakeImageSubstitutor.class.getCanonicalName())
.when(TestcontainersConfiguration.getInstance())
.getImageSubstitutorClassName();

try (GenericContainer<?> container = new GenericContainer<>(DockerImageName.parse("original"))) {
assertThatThrownBy(container::start)
.hasMessageContaining(
"imageNameSubstitutor=Chained substitutor of 'default implementation' and then 'test implementation'"
);
}
}
}