Testcontainers for ZIO

CI
Build Status

Provides idiomatic, easy-to-use ZLayers for Testcontainers-scala.

Testcontainers Best-Practices

  • Make sure your test configuration has the following settings Test / fork := true. Without this the Docker container created by the test will NOT be cleaned up until you exit SBT/the JVM process. This could quickly run your machine out of resources as you will end up with a ton of orphaned containers running.
  • Use provideLayerShared({container}.live) on your suite so that each test case isn't spinning up and down the container.

Cassandra

Release Artifacts

Provides a managed ZLayer that starts and stops a com.dimafeng.testcontainers.CassandraContainer as well as also provding a managed com.datastax.oss.driver.api.core.CqlSession.

libraryDependencies += "io.github.scottweaver" %% "zio-testcontainers-cassandra" % "0.3.0"

See test cases for example usage.

MySQL

Release Artifacts

Provides a managed ZLayer that starts and stops a com.dimafeng.testcontainers.MySQLTestContainer as well as also provding a managed java.sql.Connection.

libraryDependencies += "io.github.scottweaver" %% "zio-testcontainers-mysql" % "0.3.0"

See test cases for example usage.

PostgreSQL

Release Artifacts

Provides a managed ZLayer that starts and stops a com.dimafeng.testcontainers.PostgreSQLContainer as well as also provding a managed java.sql.Connection.

libraryDependencies += "io.github.scottweaver" %% "zio-testcontainers-postgresql" % "0.3.0"

See test cases for example usage.

Kafka

Release Artifacts

Provides a managed ZLayer that starts and stops a com.dimafeng.testcontainers.KafkaContainer.

You also have easy access to:

  • zio.kafka.consumer.ConsumerSettings via ZKafkaContainer.defaultConsumerSettings.
  • zio.kafka.consumer.ProducerSettings via ZKafkaContainer.defaultProducerSettings.

You can use these to create a zio.kafka.consumer.Consumer and/or zio.kafka.producer.Producer that can be used to interact with the Kafka container instance.

libraryDependencies += "io.github.scottweaver" %% "zio-testcontainers-kafka" % "0.3.0"

See test cases for example usage.

Database Migrations Aspect

Release Artifacts

Not really a test container, useful none the less.

The io.github.scottweaver.zio.aspect.DatabaseMigrationsAspect provides a ZIO TestAspect for running database migrations via Flyway. It seemlessly integrates with the ZMySQLContainer by using the io.github.scottweaver.zio.models.JdbcInfo provided by ZMySQLContainer.live to run your migrations.

If you are not using ZMySQLContainer you can just manually provide an appropriate JdbcInfo as a ZLayer to your tests that are using the DbMigrationAspect.

libraryDependencies += "io.github.scottweaver" %% "db-migration-aspect" % "0.3.0"

References