testcontainers / testcontainers-java

Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.
https://testcontainers.org
MIT License
7.96k stars 1.64k forks source link

Add r2dbc:tc TC_INITSCRIPT #4687

Open jamesward opened 2 years ago

jamesward commented 2 years ago

Please add a way to specify a TC_INITSCRIPT with the R2DBC automagic stuff r2dbc:tc (like exists on the jdbc:tc stuff). Thanks!

mscheong01 commented 1 year ago

Friendly note to those who are looking for an alternative: use ResourceDatabasePopulator

@Profile("test")
@Configuration
open class TestContainerPopulationConfig(
    private val connectionFactory: ConnectionFactory
) : InitializingBean {
    override fun afterPropertiesSet() {
        runBlocking {
            val databasePopulator = ResourceDatabasePopulator()
            databasePopulator.addScripts(
                ClassPathResource("db/db-schema.sql"),
            )
            databasePopulator.populate(connectionFactory).awaitFirstOrNull()
        }
    }
}

although it would still be nice if TC_INITSCRIPT works for R2DBC anyways 😃