Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.testcontainers.utility.MountableFile;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -232,6 +233,47 @@ public void testArchitectureCheck() {
}
}

@Test
public void shouldHonorUDPPorts() {
ImageFromDockerfile image = new ImageFromDockerfile("publish-multiple")
.withDockerfileFromBuilder(builder ->
builder.from("testcontainers/helloworld:1.1.0").expose(8080, 8081).build()
);

try (
GenericContainer container = new GenericContainer<>(image)
.withExposedPorts(8080, 8081)
.withCreateContainerCmdModifier(cmd -> {
//Add previously exposed ports and UDP port
List<ExposedPort> exposedPorts = new ArrayList<>();
for (ExposedPort p : cmd.getExposedPorts()) {
exposedPorts.add(p);
}
exposedPorts.add(ExposedPort.udp(99));
cmd.withExposedPorts(exposedPorts);

//Add previous port bindings and UDP port binding
Ports ports = cmd.getPortBindings();
ports.bind(ExposedPort.udp(99), Ports.Binding.empty());
cmd.withPortBindings(ports);
})
) {
container.start();
ExposedPort expectedPort = ExposedPort.udp(99);
Map<ExposedPort, Ports.Binding[]> map = container
.getContainerInfo()
.getNetworkSettings()
.getPorts()
.getBindings();

assertThat(container.getExposedPorts()).as("Two TCP ports should have been exposed").hasSize(2);
assertThat(map.get(expectedPort)).as("withExposedPorts should have exposed UDP port").isNotEmpty();
assertThat(Integer.valueOf(map.get(expectedPort)[0].getHostPortSpec()))
.as("UDP port 99 should have been mapped to a different port")
.isNotEqualTo(99);
}
}

@Test
public void shouldReturnTheProvidedImage() {
GenericContainer container = new GenericContainer(TestImages.REDIS_IMAGE);
Expand Down
Loading