|
23 | 23 | import org.testcontainers.images.builder.ImageFromDockerfile; |
24 | 24 |
|
25 | 25 | import java.util.Arrays; |
| 26 | +import java.util.ArrayList; |
26 | 27 | import java.util.List; |
27 | 28 | import java.util.Map; |
28 | 29 | import java.util.concurrent.TimeUnit; |
|
32 | 33 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
33 | 34 | import static org.hamcrest.CoreMatchers.equalTo; |
34 | 35 | import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals; |
| 36 | +import static org.rnorth.visibleassertions.VisibleAssertions.assertNotNull; |
35 | 37 | import static org.rnorth.visibleassertions.VisibleAssertions.assertThrows; |
36 | 38 | import static org.rnorth.visibleassertions.VisibleAssertions.assertTrue; |
37 | 39 | import static org.testcontainers.TestImages.TINY_IMAGE; |
@@ -146,6 +148,42 @@ public void shouldWaitUntilExposedPortIsMapped() { |
146 | 148 | } |
147 | 149 | } |
148 | 150 |
|
| 151 | + @Test |
| 152 | + public void shouldHonorUDPPorts() { |
| 153 | + ImageFromDockerfile image = new ImageFromDockerfile("publish-multiple") |
| 154 | + .withDockerfileFromBuilder(builder -> |
| 155 | + builder |
| 156 | + .from("testcontainers/helloworld:1.1.0") |
| 157 | + .expose(8080, 8081) |
| 158 | + .build() |
| 159 | + ); |
| 160 | + |
| 161 | + try ( |
| 162 | + GenericContainer container = new GenericContainer<>(image) |
| 163 | + .withExposedPorts(8080, 8081) |
| 164 | + .withCreateContainerCmdModifier(cmd -> { |
| 165 | + //Add previously exposed ports |
| 166 | + List<ExposedPort> ports = new ArrayList<>(); |
| 167 | + for (ExposedPort p : cmd.getExposedPorts()) { |
| 168 | + ports.add(p); |
| 169 | + } |
| 170 | + //Add and expose UDP port |
| 171 | + ports.add(ExposedPort.udp(99)); |
| 172 | + cmd.withExposedPorts(ports); |
| 173 | + } |
| 174 | + ) |
| 175 | + ) { |
| 176 | + |
| 177 | + container.start(); |
| 178 | + ExposedPort expectedPort = ExposedPort.udp(99); |
| 179 | + Map<ExposedPort, Ports.Binding[]> map = container.getContainerInfo().getNetworkSettings().getPorts().getBindings(); |
| 180 | + |
| 181 | + assertEquals("Two TCP ports should have been exposed.", 2, container.getExposedPorts().size()); |
| 182 | + assertNotNull("withExposedPorts should have exposed UDP port", map.get(expectedPort)); |
| 183 | + assertTrue("UDP port 99 should have been mapped to a different port", 99 != Integer.valueOf(map.get(expectedPort)[0].getHostPortSpec())); |
| 184 | + } |
| 185 | + } |
| 186 | + |
149 | 187 | static class NoopStartupCheckStrategy extends StartupCheckStrategy { |
150 | 188 |
|
151 | 189 | @Override |
|
0 commit comments