Skip to content

Commit

Permalink
Merge pull request #26 from sozu-proxy/follow-sozu-logs
Browse files Browse the repository at this point in the history
Print the sozu stdout if the test failed
  • Loading branch information
NotBad4U authored Nov 2, 2018
2 parents fd07b00 + 604d855 commit 9da72f3
Showing 1 changed file with 22 additions and 2 deletions.
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

0 comments on commit 9da72f3

Please sign in to comment.