Skip to content

Commit 56761b1

Browse files
committed
Fix tests by adding labels
1 parent 16aecea commit 56761b1

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

core/src/test/java/org/testcontainers/containers/ExposedHostTest.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
import java.io.IOException;
1717
import java.io.OutputStream;
1818
import java.net.InetSocketAddress;
19+
import java.util.HashMap;
1920
import java.util.List;
21+
import java.util.Map;
2022
import java.util.UUID;
2123

2224
import static org.assertj.core.api.Assertions.assertThat;
@@ -89,10 +91,16 @@ public void testExposedHostPortOnFixedInternalPorts() {
8991

9092
@Test
9193
public void testExposedHostWithReusableContainerAndFixedNetworkName() throws IOException, InterruptedException {
94+
Map<String, String> labels = new HashMap<>();
95+
labels.put("exposeHostPorts", "samePorts");
96+
9297
Network network = createReusableNetwork(UUID.randomUUID());
9398
Testcontainers.exposeHostPorts(server.getAddress().getPort());
9499

95-
GenericContainer<?> container = new GenericContainer<>(tinyContainerDef()).withReuse(true).withNetwork(network);
100+
GenericContainer<?> container = new GenericContainer<>(tinyContainerDef())
101+
.withLabels(labels)
102+
.withReuse(true)
103+
.withNetwork(network);
96104
container.start();
97105

98106
assertHttpResponseFromHost(container, server.getAddress().getPort());
@@ -101,6 +109,7 @@ public void testExposedHostWithReusableContainerAndFixedNetworkName() throws IOE
101109
Testcontainers.exposeHostPorts(server.getAddress().getPort());
102110

103111
GenericContainer<?> reusedContainer = new GenericContainer<>(tinyContainerDef())
112+
.withLabels(labels)
104113
.withReuse(true)
105114
.withNetwork(network);
106115
reusedContainer.start();
@@ -116,10 +125,16 @@ public void testExposedHostWithReusableContainerAndFixedNetworkName() throws IOE
116125
@Test
117126
public void testExposedHostOnFixedInternalPortsWithReusableContainerAndFixedNetworkName()
118127
throws IOException, InterruptedException {
128+
Map<String, String> labels = new HashMap<>();
129+
labels.put("exposeHostPorts", "differentPorts");
130+
119131
Network network = createReusableNetwork(UUID.randomUUID());
120132
Testcontainers.exposeHostPorts(ImmutableMap.of(server.getAddress().getPort(), 1234));
121133

122-
GenericContainer<?> container = new GenericContainer<>(tinyContainerDef()).withReuse(true).withNetwork(network);
134+
GenericContainer<?> container = new GenericContainer<>(tinyContainerDef())
135+
.withLabels(labels)
136+
.withReuse(true)
137+
.withNetwork(network);
123138
container.start();
124139

125140
assertHttpResponseFromHost(container, 1234);
@@ -128,6 +143,7 @@ public void testExposedHostOnFixedInternalPortsWithReusableContainerAndFixedNetw
128143
Testcontainers.exposeHostPorts(ImmutableMap.of(server.getAddress().getPort(), 1234));
129144

130145
GenericContainer<?> reusedContainer = new GenericContainer<>(tinyContainerDef())
146+
.withLabels(labels)
131147
.withReuse(true)
132148
.withNetwork(network);
133149
reusedContainer.start();

0 commit comments

Comments
 (0)