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

ContainerExtension afterStart doesn't have the container as parameter or receiver #115

Open
tibtof opened this issue Feb 19, 2024 · 0 comments

Comments

@tibtof
Copy link

tibtof commented Feb 19, 2024

In our project we have a lot of SharedTestContainerExtensions defined like this:

 SharedTestContainerExtension(
    GenericContainer("")
  ) {
    //set env["my.container.url"] = "http://localhost:$firstMappedPort"
  }

The problem when migrating to ContainerExtension is that the lifecycle function afterStart doesn't receive the container as a parameter. I would have expected the equivalent to be:

 ContainerExtension(
    container = GenericContainer(""),
    afterStart = {
      //set env["my.container.url"] = "http://localhost:$firstMappedPort"
    }
  )

I think that having container as receiver for the related lifecycle functions (at least for afterStart) should be useful:

class ContainerExtension<T : GenericContainer<*>>(
   private val container: T,
   private val mode: ContainerLifecycleMode = ContainerLifecycleMode.Project,
   private val beforeStart: T.() -> Unit = {},
   private val afterStart: T.() -> Unit = {},
   private val beforeTest: suspend (TestCase) -> Unit = { _ -> },
   private val afterTest: suspend T.(TestCase) -> Unit = { _ -> },
   private val beforeSpec: suspend T.(Spec) -> Unit = { _ -> },
   private val afterSpec: suspend T.(Spec) -> Unit = { _ -> },
   private val beforeShutdown: T. () -> Unit = {},
   private val afterShutdown: T.() -> Unit = {},
)
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

1 participant