-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Created method which copy file from repository to container #378
Changes from 6 commits
3902ead
6d34017
7b6b1f7
eaf07e5
01fed46
4dd3f44
3d028fc
e2f7df4
752ef0f
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package org.testcontainers.junit; | ||
|
||
import com.github.dockerjava.api.exception.NotFoundException; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.util.concurrent.Uninterruptibles; | ||
import com.mongodb.MongoClient; | ||
|
@@ -12,6 +13,7 @@ | |
import org.rnorth.ducttape.unreliables.Unreliables; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.utility.Base58; | ||
import org.testcontainers.utility.MountableFile; | ||
import org.testcontainers.utility.TestEnvironment; | ||
|
||
import java.io.*; | ||
|
@@ -320,6 +322,47 @@ public void createContainerCmdHookTest() { | |
} | ||
} | ||
|
||
@Test | ||
public void copyToContainerTest() throws Exception { | ||
|
||
try ( | ||
GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2") | ||
.withCommand("sleep 9999") | ||
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. please use |
||
){ | ||
alpineCopyToContainer.start(); | ||
|
||
final MountableFile mountableFile = MountableFile.forClasspathResource("test_copy_to_container.txt"); | ||
alpineCopyToContainer.copyFileToContainer(mountableFile, "/home/"); | ||
|
||
try (final InputStream response = alpineCopyToContainer | ||
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. Since it was requested a few times already, maybe you can add |
||
.getDockerClient() | ||
.copyArchiveFromContainerCmd(alpineCopyToContainer.getContainerId(), "/home/test_copy_to_container.txt") | ||
.exec()) { | ||
boolean bytesAvailable = response.available() > 0; | ||
assertTrue("The file wasn't copied to the container.", bytesAvailable); | ||
} | ||
} | ||
} | ||
|
||
@Test(expected = NotFoundException.class) | ||
public void copyToContainerShouldFailBecauseNoFileTest() throws NotFoundException, IOException { | ||
|
||
try ( | ||
final GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2") | ||
.withCommand("sleep 9999") | ||
) { | ||
alpineCopyToContainer.start(); | ||
|
||
try (final InputStream response = alpineCopyToContainer | ||
.getDockerClient() | ||
.copyArchiveFromContainerCmd(alpineCopyToContainer.getContainerId(), "/tmp/test.txt") | ||
.exec()) { | ||
boolean bytesAvailable = response.available() > 0; | ||
assertTrue("The file wasn't copied to the container.", bytesAvailable); | ||
} | ||
} | ||
} | ||
|
||
private BufferedReader getReaderForContainerPort80(GenericContainer container) { | ||
|
||
return Unreliables.retryUntilSuccess(10, TimeUnit.SECONDS, () -> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Some Test | ||
Message |
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.
please move the JavaDoc to
Container
interface