Skip to content

sideeffffect/zio-testcontainers

Repository files navigation

ZIO testcontainers

CI Release
Build Status Release Artifacts

ZIO wrapper for Testcontainers.

"com.github.sideeffffect" %% "zio-testcontainers" % "<version>" % Test

This library comes with toLayer extension method (behind zio.testcontainers._ import) that will turn any TestContainer into a layer that you can use in your tests.

import zio.testcontainers._

lazy val dockerCompose: ULayer[DockerComposeContainer] = ZLayer.fromTestContainer {
  new DockerComposeContainer(
    new File("docker-compose.yml"),
    List(
      ExposedService("mariadb", 3306),
      ExposedService("mailhog", 1025),
      ExposedService("mailhog", 8025),
    ),
    localCompose = false,
  )
}
...
lazy val layer = ZLayer.fromZIO {
  for {
    docker <- ZIO.service[DockerComposeContainer]
    (host, port) <- docker.getHostAndPort("mariadb")(3306)
    config = ...
  } yield config
}