@Test public void beforeShouldSuccessWhenPublishAllPortsIsTrue() throws Throwable { DockerRule httpd = DockerRule.builder() // .imageName("nginx") // .waitFor(WaitFor.tcpPort(80)) .build(); try { httpd.before(); } finally { httpd.after(); } }
@Test public void beforeShouldSuccessWhenWaitHttpPortIsExposed() throws Throwable { DockerRule httpd = DockerRule.builder() // .imageName("nginx") // .expose("8124", "80") // .waitFor(WaitFor.tcpPort(80)) .build(); try { httpd.before(); } finally { httpd.after(); } }
@Test(expected = PortNotExposedException.class) public void beforeShouldFailWhenPublishAllPortsIsFalse() throws Throwable { DockerRule httpd = DockerRule.builder() // .imageName("nginx") // .publishAllPorts(false) .waitFor(WaitFor.tcpPort(80)) .build(); try { httpd.before(); } finally { httpd.after(); } }
@Test public void shouldWaitForPort() throws Throwable { DockerRule httpd = DockerRule.builder() // .imageName("nginx") // .expose("8124", "80") // .waitFor(WaitFor.tcpPort(80)) .cmd("sh", "-c", "echo waiting...; sleep 5; echo starting...; nginx -g 'daemon off;'") .build(); try { httpd.before(); String nginxHome = "http://" + httpd.getDockerHost() + ":8124/"; log.info("homepage: {}", nginxHome); assertTrue(AssertHtml.pageContainsString(nginxHome, "Welcome to nginx!", 1, 0)); } catch (IllegalStateException e) { fail( "httpd is not available so it looks like wait for http ping is not working in rule, exception message is: " + e.getMessage()); } finally { httpd.after(); } }