-
-
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.
Fix for missed TINY_IMAGE during DockerClient initialization in case …
…of DinD environment
- Loading branch information
Showing
2 changed files
with
58 additions
and
4 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
46 changes: 46 additions & 0 deletions
46
core/src/test/java/org/testcontainers/DockerClientFactoryTest.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,46 @@ | ||
package org.testcontainers; | ||
|
||
import org.junit.Test; | ||
import org.testcontainers.dockerclient.LogToStringContainerCallback; | ||
import org.testcontainers.utility.TestcontainersConfiguration; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* Created mgorelikov on 05/04/2017 | ||
* Test for {@link DockerClientFactory}. | ||
*/ | ||
public class DockerClientFactoryTest { | ||
|
||
private static final String SUCCESS = "SUCCESS"; | ||
|
||
@Test | ||
public void runCommandInsideDockerShouldPullImageIfItDoesNotExistsLocally() { | ||
|
||
final DockerClientFactory dockFactory = DockerClientFactory.instance(); | ||
final String imageName = TestcontainersConfiguration.getInstance().getTinyImage(); | ||
//remove tiny image, so it will be pulled during next command run | ||
dockFactory.client() | ||
.removeImageCmd(imageName) | ||
.withForce(true).exec(); | ||
|
||
String result = dockFactory.runInsideDocker( | ||
cmd -> cmd.withCmd("sh", "-c", "echo '" + SUCCESS + "'"), | ||
(client, id) -> | ||
client.logContainerCmd(id) | ||
.withStdOut(true) | ||
.exec(new LogToStringContainerCallback()) | ||
.toString() | ||
); | ||
//check local image availability | ||
assertTrue(isImageAvailable(dockFactory, imageName)); | ||
assertEquals(SUCCESS + '\n', result); | ||
} | ||
|
||
private boolean isImageAvailable(DockerClientFactory dockFactory, String imageName) { | ||
return !dockFactory.client().listImagesCmd() | ||
.withImageNameFilter(imageName) | ||
.exec().isEmpty(); | ||
} | ||
} |