|
4 | 4 | import org.hamcrest.Matcher; |
5 | 5 | import org.hamcrest.core.IsCollectionContaining; |
6 | 6 | import org.junit.Test; |
| 7 | +import org.rnorth.visibleassertions.VisibleAssertions; |
7 | 8 | import org.testcontainers.containers.GenericContainer; |
8 | 9 | import org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy; |
9 | 10 | import org.testcontainers.images.builder.ImageFromDockerfile; |
10 | 11 |
|
11 | 12 | import java.io.File; |
| 13 | +import java.nio.file.Paths; |
12 | 14 | import java.util.Arrays; |
13 | 15 |
|
14 | 16 | import static org.hamcrest.CoreMatchers.allOf; |
@@ -61,6 +63,45 @@ public void simpleRecursiveFileWithPermissionTest() { |
61 | 63 | exactlyNItems(1, allOf(containsString("-rwxr-xr--"), containsString("foo")))); |
62 | 64 | } |
63 | 65 |
|
| 66 | + @Test |
| 67 | + public void transferFileDockerDaemon() { |
| 68 | + GenericContainer container = new GenericContainer( |
| 69 | + new ImageFromDockerfile() |
| 70 | + .withDockerfileFromBuilder(builder -> |
| 71 | + builder.from("alpine:3.3") |
| 72 | + .copy("bar", "/foo/") |
| 73 | + .cmd("ls", "-al", "/foo") |
| 74 | + .build() |
| 75 | + ).withFileFromFile("bar", new File("src/test/resources/mappable-resource/test-resource.txt"), |
| 76 | + 0754)) |
| 77 | + .withStartupCheckStrategy(new OneShotStartupCheckStrategy()); |
| 78 | + |
| 79 | + container.start(); |
| 80 | + String listing = container.getLogs(); |
| 81 | + |
| 82 | + assertThat("Listing shows that file is copied.", |
| 83 | + Arrays.asList(listing.split("\\n")), |
| 84 | + exactlyNItems(1, allOf(containsString("-rwxr-xr--"), containsString("bar")))); |
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + public void unableToTransferFileNamedDotToDockerDaemon() { |
| 89 | + VisibleAssertions.assertThrows("Unable to store file '" + |
| 90 | + Paths.get("src", "test", "resources", "mappable-resource", "test-resource.txt") + "' to docker path '.'", |
| 91 | + IllegalArgumentException.class, () -> { |
| 92 | + new GenericContainer( |
| 93 | + new ImageFromDockerfile() |
| 94 | + .withDockerfileFromBuilder(builder -> |
| 95 | + builder.from("alpine:3.3") |
| 96 | + .copy(".", "/foo/") |
| 97 | + .cmd("ls", "-al", "/foo") |
| 98 | + .build() |
| 99 | + ).withFileFromFile(".", new File("src/test/resources/mappable-resource/test-resource.txt"), |
| 100 | + 0754)) |
| 101 | + .withStartupCheckStrategy(new OneShotStartupCheckStrategy()); |
| 102 | + }); |
| 103 | + } |
| 104 | + |
64 | 105 | @Test |
65 | 106 | public void simpleRecursiveClasspathResourceTest() { |
66 | 107 | // This test combines the copying of classpath resources from JAR files with the recursive TAR approach, to allow JARed classpath resources to be copied in to an image |
|
0 commit comments