mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Add support for creating a container from a TestImage value
This commit improves TestImage so that an explicit image can trigger the creation of the container, with optional additional setup. This removes the need of creating additional container types for images that have multiple flavors, and to please the static method that can only create a container based on a single match. Closes gh-51082
This commit is contained in:
+4
-4
@@ -127,7 +127,7 @@ class ImportTestcontainersTests {
|
||||
static class ImportWithoutValue {
|
||||
|
||||
@ContainerAnnotation
|
||||
static PostgreSQLContainer container = TestImage.container(PostgreSQLContainer.class);
|
||||
static PostgreSQLContainer container = TestImage.forContainer(PostgreSQLContainer.class);
|
||||
|
||||
}
|
||||
|
||||
@@ -151,14 +151,14 @@ class ImportTestcontainersTests {
|
||||
@ImportTestcontainers
|
||||
static class NonStaticContainer {
|
||||
|
||||
PostgreSQLContainer container = TestImage.container(PostgreSQLContainer.class);
|
||||
PostgreSQLContainer container = TestImage.forContainer(PostgreSQLContainer.class);
|
||||
|
||||
}
|
||||
|
||||
interface ContainerDefinitions {
|
||||
|
||||
@ContainerAnnotation
|
||||
PostgreSQLContainer container = TestImage.container(PostgreSQLContainer.class);
|
||||
PostgreSQLContainer container = TestImage.forContainer(PostgreSQLContainer.class);
|
||||
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ class ImportTestcontainersTests {
|
||||
@ImportTestcontainers
|
||||
static class ContainerDefinitionsWithDynamicPropertySource {
|
||||
|
||||
static PostgreSQLContainer container = TestImage.container(PostgreSQLContainer.class);
|
||||
static PostgreSQLContainer container = TestImage.forContainer(PostgreSQLContainer.class);
|
||||
|
||||
@DynamicPropertySource
|
||||
static void containerProperties(DynamicPropertyRegistry registry) {
|
||||
|
||||
+1
-1
@@ -90,7 +90,7 @@ class TestcontainersImportWithPropertiesInjectedIntoLoadTimeWeaverAwareBeanInteg
|
||||
static class Containers {
|
||||
|
||||
@Container
|
||||
static PostgreSQLContainer container = TestImage.container(PostgreSQLContainer.class);
|
||||
static PostgreSQLContainer container = TestImage.forContainer(PostgreSQLContainer.class);
|
||||
|
||||
@DynamicPropertySource
|
||||
static void setConnectionProperties(DynamicPropertyRegistry registry) {
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ class TestcontainersLifecycleOrderIntegrationTests {
|
||||
@Bean
|
||||
@ServiceConnection
|
||||
RedisContainer redisContainer() {
|
||||
return TestImage.container(EventRecordingRedisContainer.class);
|
||||
return TestImage.forContainer(EventRecordingRedisContainer.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ class TestcontainersLifecycleOrderWithScopeIntegrationTests {
|
||||
@Scope("custom")
|
||||
@ServiceConnection
|
||||
RedisContainer redisContainer() {
|
||||
return TestImage.container(EventRecordingRedisContainer.class);
|
||||
return TestImage.forContainer(EventRecordingRedisContainer.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -55,17 +55,17 @@ class TestcontainersParallelStartupIntegrationTests {
|
||||
|
||||
@Bean
|
||||
static PostgreSQLContainer container1() {
|
||||
return TestImage.container(PostgreSQLContainer.class);
|
||||
return TestImage.forContainer(PostgreSQLContainer.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
static PostgreSQLContainer container2() {
|
||||
return TestImage.container(PostgreSQLContainer.class);
|
||||
return TestImage.forContainer(PostgreSQLContainer.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
static PostgreSQLContainer container3() {
|
||||
return TestImage.container(PostgreSQLContainer.class);
|
||||
return TestImage.forContainer(PostgreSQLContainer.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -52,13 +52,13 @@ class TestcontainersParallelStartupWithImportTestcontainersIntegrationTests {
|
||||
static class Containers {
|
||||
|
||||
@Container
|
||||
static PostgreSQLContainer container1 = TestImage.container(PostgreSQLContainer.class);
|
||||
static PostgreSQLContainer container1 = TestImage.forContainer(PostgreSQLContainer.class);
|
||||
|
||||
@Container
|
||||
static PostgreSQLContainer container2 = TestImage.container(PostgreSQLContainer.class);
|
||||
static PostgreSQLContainer container2 = TestImage.forContainer(PostgreSQLContainer.class);
|
||||
|
||||
@Container
|
||||
static PostgreSQLContainer container3 = TestImage.container(PostgreSQLContainer.class);
|
||||
static PostgreSQLContainer container3 = TestImage.forContainer(PostgreSQLContainer.class);
|
||||
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -67,7 +67,7 @@ class TestcontainersPropertySourceAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
RedisContainer redisContainer(DynamicPropertyRegistry properties) {
|
||||
RedisContainer container = TestImage.container(RedisContainer.class);
|
||||
RedisContainer container = TestImage.forContainer(RedisContainer.class);
|
||||
properties.add("container.port", container::getFirstMappedPort);
|
||||
return container;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ class TestcontainersPropertySourceAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
RedisContainer redisContainer() {
|
||||
return TestImage.container(RedisContainer.class);
|
||||
return TestImage.forContainer(RedisContainer.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
+2
-2
@@ -143,7 +143,7 @@ class ServiceConnectionAutoConfigurationTests {
|
||||
@Bean
|
||||
@ServiceConnection
|
||||
PostgreSQLContainer postgresContainer() {
|
||||
return TestImage.container(PostgreSQLContainer.class);
|
||||
return TestImage.forContainer(PostgreSQLContainer.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -176,7 +176,7 @@ class ServiceConnectionAutoConfigurationTests {
|
||||
|
||||
static class TestcontainersRootBeanDefinition extends RootBeanDefinition implements TestcontainerBeanDefinition {
|
||||
|
||||
private final PostgreSQLContainer container = TestImage.container(PostgreSQLContainer.class);
|
||||
private final PostgreSQLContainer container = TestImage.forContainer(PostgreSQLContainer.class);
|
||||
|
||||
TestcontainersRootBeanDefinition() {
|
||||
setBeanClass(PostgreSQLContainer.class);
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ class ServiceConnectionStartsConnectionOnceIntegrationTests {
|
||||
|
||||
@Container
|
||||
@ServiceConnection
|
||||
static final StartCountingPostgreSQLContainer postgres = TestImage
|
||||
static final StartCountingPostgreSQLContainer postgres = TestImage.POSTGRESQL
|
||||
.container(StartCountingPostgreSQLContainer.class);
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user