Skip to content

Commit dc4a5c8

Browse files
author
Byron David
committed
include image name in RemoteDockerImage.toString() to fix #2443
1 parent 410e96e commit dc4a5c8

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

core/src/main/java/org/testcontainers/images/RemoteDockerImage.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class RemoteDockerImage extends LazyFuture<String> {
2828

2929
private static final Duration PULL_RETRY_TIME_LIMIT = Duration.ofMinutes(2);
3030

31+
@ToString.Exclude
3132
private Future<DockerImageName> imageNameFuture;
3233

3334
@Wither
@@ -54,9 +55,8 @@ protected DockerImageName resolve() {
5455
}
5556

5657
@Override
57-
@SneakyThrows({InterruptedException.class, ExecutionException.class})
5858
protected final String resolve() {
59-
final DockerImageName imageName = imageNameFuture.get();
59+
final DockerImageName imageName = getImageName();
6060
Logger logger = DockerLoggerFactory.getLogger(imageName.toString());
6161
try {
6262
if (!imagePullPolicy.shouldPull(imageName)) {
@@ -95,4 +95,10 @@ protected final String resolve() {
9595
throw new ContainerFetchException("Failed to get Docker client for " + imageName, e);
9696
}
9797
}
98+
99+
@ToString.Include(name = "imageName", rank = 1)
100+
@SneakyThrows({InterruptedException.class, ExecutionException.class})
101+
DockerImageName getImageName() {
102+
return imageNameFuture.get();
103+
}
98104
}

core/src/test/java/org/testcontainers/containers/GenericContainerTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.github.dockerjava.api.DockerClient;
44
import com.github.dockerjava.api.command.InspectContainerResponse.ContainerState;
5-
import com.github.dockerjava.api.model.HostConfig;
65
import lombok.RequiredArgsConstructor;
76
import lombok.SneakyThrows;
87
import lombok.experimental.FieldDefaults;
@@ -54,6 +53,19 @@ public void shouldReportErrorAfterWait() {
5453
}
5554
}
5655

56+
@Test
57+
public void shouldLogImageNameWhenGetDockerImageNameFails() {
58+
// A docker image that doesn't exist is enough. The NotFoundException
59+
// that the ContainerFetchException wraps may contain the image name.
60+
// This test verifies that the ContainerFetchException itself does.
61+
String imageName = "doesNotExist";
62+
try(GenericContainer container = new GenericContainer<>(imageName)) {
63+
assertThatThrownBy(container::getDockerImageName)
64+
.isInstanceOf(ContainerFetchException.class)
65+
.hasMessageContaining(imageName);
66+
}
67+
}
68+
5769
static class NoopStartupCheckStrategy extends StartupCheckStrategy {
5870

5971
@Override

0 commit comments

Comments
 (0)