Noa*_*rec 0 scala testcontainers
使用 dimafeng 的Scala 测试容器,我可以从同一个镜像创建多个容器:
class TestWithTwoDatabases extends FunSuite with ForEachTestContainer {
protected val inputContainer: PostgreSQLContainer = PostgreSQLContainer("postgres:13.3")
protected val outputContainer: PostgreSQLContainer = PostgreSQLContainer("postgres:13.3")
override val container: MultipleContainers = MultipleContainers(inputContainer, outputContainer)
// Some integration tests
}
Run Code Online (Sandbox Code Playgroud)
如何在docker控制台中区分它们?我目前有:
CONTAINER ID IMAGE NAMES
a2bee9488c02 postgres:13.3 youthful_archimedes # I'd like to have inputContainer here
2c645ed1c54c postgres:13.3 agitated_cori # I'd like to have outputContainer here
Run Code Online (Sandbox Code Playgroud)
在 Scala 中创建容器时如何指定容器的名称?
我认为不可能做到这一点。目前尚不清楚为什么需要它。
测试容器的想法是,您可以在代码中使用它们,并且可以inputContainer根据outputContainer您的情况通过引用来区分它们。它并非旨在以引导框架的形式使用,例如docker compose,因此您可以在代码之外使用它。
此外,为容器设置固定名称将导致无法在具有共享 docker 引擎的 CI 环境中运行声明相同容器名称的测试。