testcontainers-for-zio
testcontainers-for-zio copied to clipboard
Underlying container as R
Greetings!
When I started to use testcontainers-for-zio, I've realized that I need to set custom WaitStrategy to my Postgres Container. But in the current version of library, there are not so many things I can customize in container definition using ZPostgresContainer.Settings
(only image tag and credentials, I guess).
Meanwhile, the implementation of ZKafkaContainer expects KafkaContainer.Def
as the incoming type (the R
type for ZIO) This configuration, imo, is way more flexible, cause one can provide custom container definition.
May be it would be better to redesign layers for all supported containers to make them accept <contaniner>.Def
as R
value rather then create container based on Settings object internally?
Anyway it is also possible to provide default layer, with default container.
I'm ready to contribute, if you support my idea.
Thanks in for attention!
I believe <contaniner>.Def
is all we need (whether as generic setting or container based setting). One can simply provide any setting they want using something like this:
// This is provided by default
val default = ZLayer.succeed(PostgreSQLContainer.Def())
// Use with your own settings
case class MyPostgreSQLContainerSettings(dockerImageName: DockerImageName, reuse: Boolean)
val withReUse: ZLayer[MyPostgreSQLContainerSettings, Nothing, PostgreSQLContainer.Def] =
ZLayer.fromFunction { (settings: MyPostgreSQLContainerSettings) =>
new PostgreSQLContainer.Def(dockerImageName = settings.dockerImageName) {
override def createContainer(): PostgreSQLContainer = {
val container = super.createContainer()
container.configure(_.withReuse(settings.reuse))
}
}
}
@amricko0b Sure, send up a PR and I can review it.