Created
July 8, 2020 10:49
-
-
Save hmemcpy/b7a4298988bef0a92aa12660e66cadea to your computer and use it in GitHub Desktop.
ZIO layer for Postgres test container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.dimafeng.testcontainers.PostgreSQLContainer | |
import zio.blocking.{effectBlocking, Blocking} | |
import zio.{Has, ZLayer, ZManaged} | |
object TestContainer { | |
type Postgres = Has[PostgreSQLContainer] | |
def postgres(version: Option[String] = None): ZLayer[Blocking, Throwable, Postgres] = | |
ZManaged.make { | |
effectBlocking { | |
val container = new PostgreSQLContainer( | |
dockerImageNameOverride = version | |
.map(version => s"postgres:$version") | |
.orElse(Some("postgres")) | |
) | |
container.start() | |
container | |
} | |
}(container => effectBlocking(container.stop()).orDie).toLayer | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment