Art*_*ich 8 java kotlin spring-boot testcontainers quarkus
我有以下问题。
为了加速集成测试管道,我想testcontainers使用选项集Quarkus运行。TMPFS这将强制测试容器使用内存文件系统运行数据库。
这可以根据testcontainers这样的网站轻松完成...
要将此选项传递给容器,请将 TC_TMPFS 参数添加到 URL,如下所示: jdbc:tc:postgresql:9.6.8:///databasename?TC_TMPFS=/testtmpfs:rw
看来问题已经解决了。这就是它应该如何工作Spring Boot
然而,Quarkus在他们的文档中,它说了以下内容......
所有基于容器的服务都使用测试容器运行。尽管可以在 application.properties 文件中设置额外的 URL 属性,但不支持特定的 testcontainers 属性,例如 TC_INITSCRIPT、TC_INITFUNCTION、TC_DAEMON、TC_TMPFS。
我的问题是:
如何解决这个问题?如何运行将安装在 TMPFS 上的测试容器?
QuarkusTestResourceLifecycleManager 您可以尝试使用指南设置 TMPFS 。
Quarkus Kotlin 示例:
class DatabaseTestLifeCycleManager : QuarkusTestResourceLifecycleManager {
private val postgresDockerImage = DockerImageName.parse("postgres:latest")
override fun start(): MutableMap<String, String>? {
val container = startPostgresContainer()
return mutableMapOf(
"quarkus.datasource.username" to container.username,
"quarkus.datasource.password" to container.password,
"quarkus.datasource.jdbc.url" to container.jdbcUrl
)
}
private fun startPostgresContainer(): PostgreSQLContainer<out PostgreSQLContainer<*>> {
val container = PostgreSQLContainer(postgresDockerImage)
.withDatabaseName("dataBaseName")
.withUsername("username")
.withPassword("password")
.withEnv(mapOf("PGDATA" to "/var/lib/postgresql/data"))
.withTmpFs(mapOf("/var/lib/postgresql/data" to "rw"))
container.start()
return container
}
override fun stop() {
// close container
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1783 次 |
| 最近记录: |