-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include image name in RemoteDockerImage#toString (#2558)
* clean up imports in GenericContainer * include image name in RemoteDockerImage.toString() to fix #2443 * test RemoteDockerImage directly * handle failures getting the image name * use completeExceptionally instead of mocking * tweak assertions * more assertion tweaks * add isDone check to RemoteDockerImage.toString -- still figuring out why test fails * go back to using lombok @tostring, exclude dockerClient while we're at it * use `Futures.lazyTransform` that also proxies `isDone` * `imageNameToString` should not be public * Include the message on error Co-authored-by: Byron David <david.byron@avast.com> Co-authored-by: David Byron <dbyron@dbyron.com>
- Loading branch information
1 parent
34b8d7e
commit 95c828d
Showing
3 changed files
with
69 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
core/src/test/java/org/testcontainers/images/RemoteDockerImageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.testcontainers.images; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import org.junit.Test; | ||
import org.testcontainers.utility.Base58; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class RemoteDockerImageTest { | ||
|
||
@Test | ||
public void toStringContainsOnlyImageName() { | ||
String imageName = Base58.randomString(8).toLowerCase(); | ||
RemoteDockerImage remoteDockerImage = new RemoteDockerImage(imageName); | ||
assertThat(remoteDockerImage.toString(), containsString("imageName=" + imageName)); | ||
} | ||
|
||
@Test | ||
public void toStringWithExceptionContainsOnlyImageNameFuture() { | ||
CompletableFuture<String> imageNameFuture = new CompletableFuture<>(); | ||
imageNameFuture.completeExceptionally(new RuntimeException("arbitrary")); | ||
|
||
RemoteDockerImage remoteDockerImage = new RemoteDockerImage(imageNameFuture); | ||
assertThat(remoteDockerImage.toString(), containsString("imageName=java.lang.RuntimeException: arbitrary")); | ||
} | ||
|
||
@Test(timeout=5000L) | ||
public void toStringDoesntResolveImageNameFuture() { | ||
CompletableFuture<String> imageNameFuture = new CompletableFuture<>(); | ||
|
||
// verify that we've set up the test properly | ||
assertFalse(imageNameFuture.isDone()); | ||
|
||
RemoteDockerImage remoteDockerImage = new RemoteDockerImage(imageNameFuture); | ||
assertThat(remoteDockerImage.toString(), containsString("imageName=<resolving>")); | ||
|
||
// Make sure the act of calling toString doesn't resolve the imageNameFuture | ||
assertFalse(imageNameFuture.isDone()); | ||
|
||
String imageName = Base58.randomString(8).toLowerCase(); | ||
imageNameFuture.complete(imageName); | ||
assertThat(remoteDockerImage.toString(), containsString("imageName=" + imageName)); | ||
} | ||
} |