Home > front end >  Specify container name using testcontainers in Scala
Specify container name using testcontainers in Scala

Time:03-18

Using dimafeng's test containers for Scala I can create several containers from the same image:

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
}

How distinguish them within the docker console? I currently have:

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

How can I specify the containers' names when creating them in Scala?

CodePudding user response:

I don't think it is possible to do it. And it is not clear why you need it.

The idea of test containers is that you'd use them in your code and you can distinguish them by reference, inputContainer and outputContainer in you case. It is not designed to be used as a form of booting framework, like docker compose, so you can use it externally outside of your code.

Also setting a fixed name to the container will make it impossible to run tests that claim same container name in CI environment with shared docker engine.

  • Related