Skip to content

Commit

Permalink
Clean up following review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gorelikov committed Apr 5, 2017
1 parent 9ae6415 commit 690d369
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ public DockerClient client() {
" Total Memory: " + dockerInfo.getMemTotal() / (1024 * 1024) + " MB");

checkVersion(version.getVersion());

// Pull the image we use to perform some checks
checkAndPullImage(client, TINY_IMAGE);

checkDiskSpaceAndHandleExceptions(client);
preconditionsChecked = true;
}
Expand Down
24 changes: 4 additions & 20 deletions core/src/test/java/org/testcontainers/DockerClientFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,27 @@
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() {
public void runCommandInsideDockerShouldNotFailIfImageDoesNotExistsLocally() {

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)
.removeImageCmd(TestcontainersConfiguration.getInstance().getTinyImage())
.withForce(true).exec();

String result = dockFactory.runInsideDocker(
cmd -> cmd.withCmd("sh", "-c", "echo '" + SUCCESS + "'"),
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();
}
}

0 comments on commit 690d369

Please sign in to comment.