-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
#323 Fix for missed TINY_IMAGE during DockerClient initialization #324
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. auto-generated doc comment. I would remove it, doesn't help here. However, you can include yourself in contributors list :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. Sorry for that |
||
* Test for {@link DockerClientFactory}. | ||
*/ | ||
public class DockerClientFactoryTest { | ||
|
||
private static final String SUCCESS = "SUCCESS"; | ||
|
||
@Test | ||
public void runCommandInsideDockerShouldPullImageIfItDoesNotExistsLocally() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this test does too much. What it should test that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, I kept here only |
||
|
||
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(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkDiskSpaceAndHandleExceptions
callscheckDiskSpace
which callsrunInsideDocker
which callscheckAndPullImage
after your change.It means that we could remove
checkAndPullImage
from here and inlinecheckAndPullImage
inrunInsideDocker
.WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed that call, but kept the method checkAndPullImage. I don't like long methods, so i would keep the separate method, if you don't mind :)