Skip to content

Commit

Permalink
Manually write a file inside the container
Browse files Browse the repository at this point in the history
  • Loading branch information
kiview committed Mar 14, 2024
1 parent 93bfdc5 commit 54f1528
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/test/java/org/testcontainers/repro/ReproExampleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.Container;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.PostgreSQLContainer;

Expand All @@ -17,7 +18,7 @@
public class ReproExampleTest {

@Test
public void bindMountLogFiles() throws IOException {
public void bindMountLogFiles() throws IOException, InterruptedException {
try (
GenericContainer<?> container = new GenericContainer<>("nginx:1.19.0-alpine")
.withExposedPorts(80)
Expand All @@ -33,10 +34,16 @@ public void bindMountLogFiles() throws IOException {
long now = System.currentTimeMillis();
performRequestAgainstContainer(container, "/foobar/" + now);

// manually write a file into the container
Container.ExecResult result = container.execInContainer("/bin/sh", "-c", "echo '" + now + " Hello, World!' >> /var/log/nginx/test.log");

// check that nginx/error.log in the project directory contains the now timestamp
String errorLog = System.getProperty("user.dir") + "/nginx/error.log";
String errorLogContents = new String(java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(errorLog)));
Assert.assertTrue(errorLogContents.contains(Long.toString(now)));

String testLog = System.getProperty("user.dir") + "/nginx/test.log";
String testLogContents = new String(java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(testLog)));
Assert.assertTrue(testLogContents.contains(Long.toString(now)));

}

Expand Down

0 comments on commit 54f1528

Please sign in to comment.