Skip to content

Commit

Permalink
Document DockerComposeContainer usage
Browse files Browse the repository at this point in the history
Add an example of defining and starting a container, from a docker-compose file, using the new API (testcontainers#78, support added testcontainers#100)
  • Loading branch information
kittsville committed Dec 23, 2020
1 parent 1c36c12 commit 920311c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,19 +407,20 @@ If you want to use multiple containers in your test:
class ExampleSpec extends FlatSpec with TestContainersForAll {

// First of all, you need to declare, which containers you want to use
override type Containers = MySQLContainer and PostgreSQLContainer
override type Containers = MySQLContainer and PostgreSQLContainer and DockerComposeContainer

// After that, you need to describe, how you want to start them,
// In this method you can use any intermediate logic.
// You can pass parameters between containers, for example.
override def startContainers(): Containers = {
val container1 = MySQLContainer.Def().start()
val container2 = PostgreSQLContainer.Def().start()
container1 and container2
val container3 = DockerComposeContainer.Def(ComposeFile(Left(new File("docker-compose.yml")))).start()
container1 and container2 and container3
}

// `withContainers` function supports multiple containers:
it should "test" in withContainers { case mysqlContainer and pgContainer =>
it should "test" in withContainers { case mysqlContainer and pgContainer and dcContainer =>
// Inside your test body you can do with your containers whatever you want to
assert(mysqlContainer.jdbcUrl.nonEmpty && pgContainer.jdbcUrl.nonEmpty)
}
Expand Down Expand Up @@ -506,20 +507,21 @@ If you want to use multiple containers for all tests in your suite:
class ExampleSpec extends FunSuite with TestContainersForAll {

// First of all, you need to declare, which containers you want to use
override type Containers = MySQLContainer and PostgreSQLContainer
override type Containers = MySQLContainer and PostgreSQLContainer and DockerComposeContainer

// After that, you need to describe, how you want to start them,
// In this method you can use any intermediate logic.
// You can pass parameters between containers, for example.
override def startContainers(): Containers = {
val container1 = MySQLContainer.Def().start()
val container2 = PostgreSQLContainer.Def().start()
container1 and container2
val container3 = DockerComposeContainer.Def(ComposeFile(Left(new File("docker-compose.yml")))).start()
container1 and container2 and container3
}

// `withContainers` function supports multiple containers:
test("test") {
withContainers { case mysqlContainer and pgContainer =>
withContainers { case mysqlContainer and pgContainer and dcContainer =>
// Inside your test body you can do with your containers whatever you want to
assert(mysqlContainer.jdbcUrl.nonEmpty && pgContainer.jdbcUrl.nonEmpty)
}
Expand Down

0 comments on commit 920311c

Please sign in to comment.