-
-
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
Created method which copy file from repository to container #378
Closed
lukidzi
wants to merge
9
commits into
testcontainers:master
from
lukidzi:feature/add_copy_to_container_method
Closed
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3902ead
First concept. Created method which copy file from repository which w…
lukidzi 6d34017
Added unit test which check if file exist on container. Made changes …
lukidzi 7b6b1f7
Code review. Moved container creation to try-with-resources and chang…
lukidzi eaf07e5
Removed ClassRule level container creation
lukidzi 01fed46
Added code review changes.
lukidzi 4dd3f44
Added changes to java doc
lukidzi 3d028fc
Added copy from container method
lukidzi e2f7df4
Code review changes
lukidzi 752ef0f
Changed to temp folder
lukidzi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,17 +1,20 @@ | ||
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; | ||
import com.mongodb.client.MongoCollection; | ||
import com.mongodb.client.MongoDatabase; | ||
import com.rabbitmq.client.*; | ||
import org.apache.commons.io.FileUtils; | ||
import org.bson.Document; | ||
import org.junit.*; | ||
import org.rnorth.ducttape.RetryCountExceededException; | ||
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.*; | ||
|
@@ -39,15 +42,14 @@ public class GenericContainerRuleTest { | |
private static final String RABBITMQ_TEST_MESSAGE = "Hello world"; | ||
private static final int RABBITMQ_PORT = 5672; | ||
private static final int MONGO_PORT = 27017; | ||
|
||
private static final File CONTENT_FOLDER = new File(System.getProperty("user.home") + "/.tmp-test-container"); | ||
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. Why don't you use something like 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, my bad |
||
/* | ||
* Test data setup | ||
*/ | ||
@BeforeClass | ||
public static void setupContent() throws FileNotFoundException { | ||
File contentFolder = new File(System.getProperty("user.home") + "/.tmp-test-container"); | ||
contentFolder.mkdir(); | ||
writeStringToFile(contentFolder, "file", "Hello world!"); | ||
CONTENT_FOLDER.mkdir(); | ||
writeStringToFile(CONTENT_FOLDER, "file", "Hello world!"); | ||
} | ||
|
||
/** | ||
|
@@ -320,6 +322,51 @@ public void createContainerCmdHookTest() { | |
} | ||
} | ||
|
||
@Test | ||
public void copyToContainerTest() throws Exception { | ||
|
||
try (final GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2") | ||
.withCommand("top")){ | ||
alpineCopyToContainer.start(); | ||
|
||
final MountableFile mountableFile = MountableFile.forClasspathResource("test_copy_to_container.txt"); | ||
alpineCopyToContainer.copyFileToContainer(mountableFile, "/home/"); | ||
alpineCopyToContainer.copyFileFromContainer("/home/test_copy_to_container.txt", | ||
CONTENT_FOLDER.getAbsolutePath() + "/test_copy_to_container.txt"); | ||
|
||
File expectedFile = new File(mountableFile.getResolvedPath()); | ||
File actualFile = new File(CONTENT_FOLDER.getAbsolutePath() + "/test_copy_to_container.txt"); | ||
assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile,actualFile)); | ||
} | ||
} | ||
|
||
@Test(expected = NotFoundException.class) | ||
public void copyFromContainerShouldFailBecauseNoFileTest() throws NotFoundException, IOException, InterruptedException { | ||
|
||
try (final GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2") | ||
.withCommand("top")) { | ||
alpineCopyToContainer.start(); | ||
alpineCopyToContainer.copyFileFromContainer("/home/test.txt", "src/test/resources/copy-from/test.txt"); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldCopyFileFromContainerTest() throws IOException, InterruptedException { | ||
try (final GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2") | ||
.withCommand("top")) { | ||
|
||
alpineCopyToContainer.start(); | ||
final MountableFile mountableFile = MountableFile.forClasspathResource("test_copy_to_container.txt"); | ||
alpineCopyToContainer.copyFileToContainer(mountableFile, "/home/"); | ||
alpineCopyToContainer.copyFileFromContainer("/home/test_copy_to_container.txt", | ||
CONTENT_FOLDER.getAbsolutePath() + "/test_copy_from_container.txt"); | ||
|
||
File expectedFile = new File(mountableFile.getResolvedPath()); | ||
File actualFile = new File(CONTENT_FOLDER.getAbsolutePath() + "/test_copy_from_container.txt"); | ||
assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile,actualFile)); | ||
} | ||
} | ||
|
||
private BufferedReader getReaderForContainerPort80(GenericContainer container) { | ||
|
||
return Unreliables.retryUntilSuccess(10, TimeUnit.SECONDS, () -> { | ||
|
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,2 @@ | ||
Some Test | ||
Message |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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