-
Notifications
You must be signed in to change notification settings - Fork 0
chore: integrate Testcontainers for automatic Docker Compose management in integration tests #495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2b8241c
57d6349
547b803
62d73f9
c5ba578
37db849
7bce671
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "java.configuration.updateBuildConfiguration": "automatic" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,14 @@ | ||
| services: | ||
| app: | ||
| ports: !override | ||
| ports: | ||
| - "8080" | ||
| postgres: | ||
| ports: !override | ||
| ports: | ||
| - "5432" | ||
| mock-file-api: | ||
| ports: !override | ||
| ports: | ||
| - "8080" | ||
| volumes: [] | ||
| mock-oidc: | ||
| ports: !override | ||
| ports: | ||
| - "5556" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package hu.bsstudio.bssweb | ||
|
|
||
| import org.springframework.boot.test.context.TestConfiguration | ||
| import org.springframework.context.annotation.Bean | ||
| import org.springframework.test.context.DynamicPropertyRegistry | ||
| import org.springframework.test.context.DynamicPropertySource | ||
| import org.testcontainers.containers.DockerComposeContainer | ||
| import java.io.File | ||
|
|
||
| @TestConfiguration | ||
| class TestContainerConfiguration { | ||
|
|
||
| @Bean | ||
| fun dockerComposeContainer(): DockerComposeContainer<*> { | ||
| return DockerComposeContainer(File("../docker-compose.yml"), File("../docker-compose.ci.yml")) | ||
| .withExposedService("postgres", 5432) | ||
| .withExposedService("app", 8080) | ||
| .withOptions("--profile app") | ||
| .withBuild(true) | ||
| } | ||
|
|
||
| @DynamicPropertySource | ||
| fun containerPropertyConfigurer(registry: DynamicPropertyRegistry, dockerComposeContainer: DockerComposeContainer<*>) { | ||
| val postgresHost = dockerComposeContainer.getServiceHost("postgres", 5432) | ||
| val postgresPort = dockerComposeContainer.getServicePort("postgres", 5432) | ||
| val appHost = dockerComposeContainer.getServiceHost("app", 8080) | ||
| val appPort = dockerComposeContainer.getServicePort("app", 8080) | ||
|
|
||
| registry.add("spring.datasource.url") { | ||
| "jdbc:postgresql://$postgresHost:$postgresPort/bss?currentSchema=private" | ||
| } | ||
| registry.add("spring.datasource.username") { "user" } | ||
| registry.add("spring.datasource.password") { "password" } | ||
| registry.add("spring.flyway.enabled") { "false" } | ||
| registry.add("bss.client.url") { "http://$appHost:$appPort" } | ||
| } | ||
|
Comment on lines
+22
to
+36
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DynamicPropertySource cannot inject beans as method parameters. The To fix this, either:
Option 1 (Recommended): Use constructor injection @TestConfiguration
-class TestContainerConfiguration {
+class TestContainerConfiguration(
+ private val dockerComposeContainer: DockerComposeContainer<*>
+) {
- @Bean
- fun dockerComposeContainer(): DockerComposeContainer<*> {
- return DockerComposeContainer(File("../docker-compose.yml"), File("../docker-compose.ci.yml"))
- .withExposedService("postgres", 5432)
- .withExposedService("app", 8080)
- .withOptions("--profile app")
- .withBuild(true)
- }
-
@DynamicPropertySource
- fun containerPropertyConfigurer(registry: DynamicPropertyRegistry, dockerComposeContainer: DockerComposeContainer<*>) {
+ fun containerPropertyConfigurer(registry: DynamicPropertyRegistry) {
val postgresHost = dockerComposeContainer.getServiceHost("postgres", 5432)
val postgresPort = dockerComposeContainer.getServicePort("postgres", 5432)
val appHost = dockerComposeContainer.getServiceHost("app", 8080)
val appPort = dockerComposeContainer.getServicePort("app", 8080)
registry.add("spring.datasource.url") {
"jdbc:postgresql://$postgresHost:$postgresPort/bss?currentSchema=private"
}
registry.add("spring.datasource.username") { "user" }
registry.add("spring.datasource.password") { "password" }
registry.add("spring.flyway.enabled") { "false" }
registry.add("bss.client.url") { "http://$appHost:$appPort" }
}
+
+ companion object {
+ @Bean
+ @JvmStatic
+ fun dockerComposeContainer(): DockerComposeContainer<*> {
+ return DockerComposeContainer(File("../docker-compose.yml"), File("../docker-compose.ci.yml"))
+ .withExposedService("postgres", 5432)
+ .withExposedService("app", 8080)
+ .withOptions("--profile app")
+ .withBuild(true)
+ }
+ }
}
🤖 Prompt for AI Agents |
||
| } | ||
|
Comment on lines
+1
to
+37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix Kotlin formatting to resolve spotlessKotlinCheck failure. The pipeline indicates formatting violations in this file. Run the following command to automatically fix the formatting: #!/bin/bash
./gradlew spotlessApply🧰 Tools🪛 GitHub Actions: Gradle[error] 1-1: integration:spotlessKotlinCheck failed: format violations detected in TestContainerConfiguration.kt. There are formatting/value assignment style issues in dockerComposeContainer and containerPropertyConfigurer definitions. Run './gradlew spotlessApply' to fix formatting. 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extraneous blank line to fix spotlessKotlinCheck failure.
The pipeline failure indicates formatting violations including an extraneous blank line near the class declaration.
@SpringJUnitConfig(classes = [TestContainerConfiguration::class, BssFeignConfig::class, DataConfig::class]) - open class IntegrationTest {🤖 Prompt for AI Agents