TestContainer Postgres

This commit is contained in:
2025-09-13 14:47:02 +02:00
parent ae47c718e5
commit ceb8bcdbc6
7 changed files with 160 additions and 1 deletions

View File

@@ -0,0 +1,21 @@
package ltd.lulz.test.container.extension
import ltd.lulz.test.container.postgres.TestContainerPostgres
import org.junit.jupiter.api.extension.BeforeAllCallback
import org.junit.jupiter.api.extension.ExtensionContext
import org.springframework.boot.test.util.TestPropertyValues
import org.springframework.context.ApplicationContextInitializer
import org.springframework.context.ConfigurableApplicationContext
class PostgresTestExtension : BeforeAllCallback, ApplicationContextInitializer<ConfigurableApplicationContext> {
override fun initialize(applicationContext: ConfigurableApplicationContext) {
TestPropertyValues.of(TestContainerPostgres.props()).applyTo(applicationContext.environment)
}
override fun beforeAll(context: ExtensionContext) {
if (!TestContainerPostgres.postgres.isRunning) {
TestContainerPostgres.postgres.start()
}
}
}