1616import java .io .IOException ;
1717import java .io .OutputStream ;
1818import java .net .InetSocketAddress ;
19+ import java .util .HashMap ;
1920import java .util .List ;
21+ import java .util .Map ;
2022import java .util .UUID ;
2123
2224import 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