Skip to content

Commit

Permalink
Revert "Example and docs for ability to copy to and from container for
Browse files Browse the repository at this point in the history
  • Loading branch information
rnorth committed May 3, 2020
1 parent 7c761a9 commit 0050e70
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,62 +1,40 @@
package org.testcontainers.junit;

import com.google.common.io.Files;
import com.google.common.io.Resources;
import org.junit.Test;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.SelinuxContext;
import org.testcontainers.utility.MountableFile;

import java.io.File;
import java.io.IOException;
import java.util.Map;

import static org.junit.Assert.assertArrayEquals;
import static org.rnorth.visibleassertions.VisibleAssertions.assertFalse;
import static org.rnorth.visibleassertions.VisibleAssertions.assertTrue;

public class CopyFileToContainerTest {
public static final String destinationOnHost = "/tmp/test-resource-in-host.txt";
private static String directoryInContainer = "/tmp/mappable-resource/";
private static String containerPath = "/tmp/mappable-resource/";
private static String fileName = "test-resource.txt";

@Test
public void checkFileCopied() throws IOException, InterruptedException {
try (
// copyToContainer {
GenericContainer container = new GenericContainer()
.withCommand("sleep", "3000")
// withCopyFileToContainer ensure that a file or directory will be copied to the container
// before starting. In this case, we map a classpath directory to a directory inside the container
.withCopyFileToContainer(MountableFile.forClasspathResource("/mappable-resource/"), directoryInContainer)
// }
.withCopyFileToContainer(MountableFile.forClasspathResource("/mappable-resource/"), containerPath)
) {
container.start();

// at this point directoryInContainer should exist, and should contain copies of file(s)
String filesList = container.execInContainer("ls", directoryInContainer).getStdout();
String filesList = container.execInContainer("ls", "/tmp/mappable-resource").getStdout();
assertTrue("file list contains the file", filesList.contains(fileName));

// ...

// copyFromContainer {
container.copyFileFromContainer(directoryInContainer + fileName, destinationOnHost);
// }
}

assertArrayEquals(
Files.toByteArray(new File(destinationOnHost)),
Resources.toByteArray(CopyFileToContainerTest.class.getResource("/mappable-resource/" + fileName))
);
}

@Test
public void shouldUseCopyForReadOnlyClasspathResources() throws Exception {
try (
GenericContainer container = new GenericContainer()
.withCommand("sleep", "3000")
.withClasspathResourceMapping("/mappable-resource/", directoryInContainer, BindMode.READ_ONLY)
.withClasspathResourceMapping("/mappable-resource/", containerPath, BindMode.READ_ONLY)
) {
container.start();
String filesList = container.execInContainer("ls", "/tmp/mappable-resource").getStdout();
Expand Down
16 changes: 0 additions & 16 deletions docs/features/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,3 @@ new GenericContainer(...)
"/etc/redis.conf",
BindMode.READ_ONLY)
```

## Copying files to and from containers

Files can be copied into the container before startup, or can be copied from the container after the container has started.

### Copying to a container before startup

<!--codeinclude-->
[Copying files to a container](../../core/src/test/java/org/testcontainers/junit/CopyFileToContainerTest.java) inside_block:copyToContainer
<!--/codeinclude-->

### Copying a file from a running container

<!--codeinclude-->
[Copying files from a container](../../core/src/test/java/org/testcontainers/junit/CopyFileToContainerTest.java) inside_block:copyFromContainer
<!--/codeinclude-->

0 comments on commit 0050e70

Please sign in to comment.