-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add getLogs() to GenericContainer, allowing all logs to be retrieved (#…
- Loading branch information
Showing
9 changed files
with
216 additions
and
86 deletions.
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
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
72 changes: 72 additions & 0 deletions
72
core/src/test/java/org/testcontainers/containers/output/ContainerLogsTest.java
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,72 @@ | ||
package org.testcontainers.containers.output; | ||
|
||
import org.junit.Test; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy; | ||
|
||
import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals; | ||
import static org.rnorth.visibleassertions.VisibleAssertions.assertTrue; | ||
import static org.testcontainers.containers.output.OutputFrame.OutputType.STDERR; | ||
import static org.testcontainers.containers.output.OutputFrame.OutputType.STDOUT; | ||
|
||
public class ContainerLogsTest { | ||
|
||
@Test | ||
public void getLogsReturnsAllLogsToDate() { | ||
try (GenericContainer container = shortLivedContainer()) { | ||
container.start(); | ||
|
||
// docsGetAllLogs { | ||
final String logs = container.getLogs(); | ||
// } | ||
assertEquals("stdout and stderr are reflected in the returned logs", "stdout\nstderr", logs); | ||
} | ||
} | ||
|
||
@Test | ||
public void getLogsReturnsStdOutToDate() { | ||
try (GenericContainer container = shortLivedContainer()) { | ||
container.start(); | ||
|
||
// docsGetStdOut { | ||
final String logs = container.getLogs(STDOUT); | ||
// } | ||
assertEquals("stdout and stderr are reflected in the returned logs", "stdout", logs); | ||
} | ||
} | ||
|
||
@Test | ||
public void getLogsReturnsStdErrToDate() { | ||
try (GenericContainer container = shortLivedContainer()) { | ||
container.start(); | ||
|
||
// docsGetStdErr { | ||
final String logs = container.getLogs(STDERR); | ||
// } | ||
assertEquals("stdout and stderr are reflected in the returned logs", "stderr", logs); | ||
} | ||
} | ||
|
||
@Test | ||
public void getLogsForLongRunningContainer() throws InterruptedException { | ||
try (GenericContainer container = longRunningContainer()) { | ||
container.start(); | ||
|
||
Thread.sleep(1000L); | ||
|
||
final String logs = container.getLogs(STDOUT); | ||
assertTrue("stdout is reflected in the returned logs for a running container", logs.contains("seq=0")); | ||
} | ||
} | ||
|
||
private static GenericContainer shortLivedContainer() { | ||
return new GenericContainer("alpine:3.3") | ||
.withCommand("/bin/sh", "-c", "echo -n 'stdout' && echo -n 'stderr' 1>&2") | ||
.withStartupCheckStrategy(new OneShotStartupCheckStrategy()); | ||
} | ||
|
||
private static GenericContainer longRunningContainer() { | ||
return new GenericContainer("alpine:3.3") | ||
.withCommand("ping -c 100 127.0.0.1"); | ||
} | ||
} |
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
Oops, something went wrong.