|
23 | 23 | import org.testcontainers.images.RemoteDockerImage;
|
24 | 24 | import org.testcontainers.images.builder.ImageFromDockerfile;
|
25 | 25 | import org.testcontainers.images.builder.Transferable;
|
| 26 | +import org.testcontainers.utility.DockerImageName; |
26 | 27 | import org.testcontainers.utility.MountableFile;
|
27 | 28 |
|
28 | 29 | import java.util.Arrays;
|
@@ -231,6 +232,30 @@ public void shouldReturnTheProvidedImage() {
|
231 | 232 | assertThat(container.getImage().get()).isEqualTo("alpine:3.16");
|
232 | 233 | }
|
233 | 234 |
|
| 235 | + @Test |
| 236 | + public void shouldContainDefaultNetworkAlias() { |
| 237 | + try (GenericContainer<?> container = new GenericContainer<>("testcontainers/helloworld:1.1.0")) { |
| 238 | + container.start(); |
| 239 | + assertThat(container.getNetworkAliases()).hasSize(1); |
| 240 | + } |
| 241 | + } |
| 242 | + |
| 243 | + @Test |
| 244 | + public void shouldContainDefaultNetworkAliasWhenUsingGenericContainer() { |
| 245 | + try (HelloWorldContainer container = new HelloWorldContainer("testcontainers/helloworld:1.1.0")) { |
| 246 | + container.start(); |
| 247 | + assertThat(container.getNetworkAliases()).hasSize(1); |
| 248 | + } |
| 249 | + } |
| 250 | + |
| 251 | + @Test |
| 252 | + public void shouldContainDefaultNetworkAliasWhenUsingContainerDef() { |
| 253 | + try (TcHelloWorldContainer container = new TcHelloWorldContainer("testcontainers/helloworld:1.1.0")) { |
| 254 | + container.start(); |
| 255 | + assertThat(container.getNetworkAliases()).hasSize(1); |
| 256 | + } |
| 257 | + } |
| 258 | + |
234 | 259 | static class NoopStartupCheckStrategy extends StartupCheckStrategy {
|
235 | 260 |
|
236 | 261 | @Override
|
@@ -267,4 +292,31 @@ protected void waitUntilReady() {
|
267 | 292 | throw new IllegalStateException("Nope!");
|
268 | 293 | }
|
269 | 294 | }
|
| 295 | + |
| 296 | + static class HelloWorldContainer extends GenericContainer<HelloWorldContainer> { |
| 297 | + |
| 298 | + public HelloWorldContainer(String image) { |
| 299 | + super(DockerImageName.parse(image)); |
| 300 | + withExposedPorts(8080); |
| 301 | + } |
| 302 | + } |
| 303 | + |
| 304 | + static class TcHelloWorldContainer extends GenericContainer<HelloWorldContainer> { |
| 305 | + |
| 306 | + public TcHelloWorldContainer(String image) { |
| 307 | + super(DockerImageName.parse(image)); |
| 308 | + } |
| 309 | + |
| 310 | + @Override |
| 311 | + ContainerDef createContainerDef() { |
| 312 | + return new HelloWorldContainerDef(); |
| 313 | + } |
| 314 | + |
| 315 | + class HelloWorldContainerDef extends ContainerDef { |
| 316 | + |
| 317 | + HelloWorldContainerDef() { |
| 318 | + addExposedTcpPort(8080); |
| 319 | + } |
| 320 | + } |
| 321 | + } |
270 | 322 | }
|
0 commit comments