Skip to content
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

Print the sozu stdout if the test failed #26

Merged
merged 1 commit into from
Nov 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/test/java/SozuContainerTest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import org.apache.http.HttpResponse;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import org.junit.Rule;
import org.junit.Test;
import org.junit.*;
import org.junit.rules.TestName;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.testcontainers.containers.output.OutputFrame;
import org.testcontainers.containers.output.ToStringConsumer;
import org.testcontainers.shaded.org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -43,8 +45,26 @@ public class SozuContainerTest {
@Rule
public SozuContainer sozuContainer = SozuContainer.newSozuContainer();

private ToStringConsumer toStringSozuConsumer;

@Rule
// Use the test watcher to print the logs of sozu if a test failed
public TestWatcher watcher = new TestWatcher() {
@Override
protected void failed(Throwable e, Description description) {
String sozuLogs = toStringSozuConsumer.toUtf8String();
System.out.println(sozuLogs);
}
};

public SozuContainerTest() throws URISyntaxException {}

@Before
public void beforeEach() {
toStringSozuConsumer = new ToStringConsumer();
sozuContainer.followOutput(toStringSozuConsumer, OutputFrame.OutputType.STDOUT);
}

@Test
public void testCorrectResponseFromSozu() throws Exception {
URL sozuUrl = sozuContainer.getBaseUrl("http", SozuContainer.DEFAULT_HTTP_PORT);
Expand Down