Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Underlying container as R #36

Open
amricko0b opened this issue Aug 22, 2022 · 2 comments
Open

Underlying container as R #36

amricko0b opened this issue Aug 22, 2022 · 2 comments

Comments

@amricko0b
Copy link

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!

@endertunc
Copy link

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))
      }
    }
  }

 

@scottweaver
Copy link
Owner

@amricko0b Sure, send up a PR and I can review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants