This repository was archived by the owner on Feb 16, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +10
-9
lines changed
main/kotlin/io/kotest/extensions/testcontainers
test/kotlin/io/kotest/extensions/testcontainers Expand file tree Collapse file tree 2 files changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ import org.testcontainers.containers.GenericContainer
5353 * @param afterShutdown a callback that is invoked only once, just after the container is stopped.
5454 * If the container is never started, this callback will not be invoked.
5555 */
56- class ContainerExtension <T : GenericContainer <T >>(
56+ class ContainerExtension <T : GenericContainer <* >>(
5757 private val container : T ,
5858 private val mode : ContainerLifecycleMode = ContainerLifecycleMode .Project ,
5959 private val beforeStart : () -> Unit = {},
@@ -86,19 +86,19 @@ class ContainerExtension<T : GenericContainer<T>>(
8686 }
8787
8888 override suspend fun beforeTest (testCase : TestCase ) {
89- beforeTest(testCase)
89+ beforeTest.invoke (testCase)
9090 }
9191
9292 override suspend fun afterTest (testCase : TestCase , result : TestResult ) {
9393 afterTest(testCase)
9494 }
9595
9696 override suspend fun beforeSpec (spec : Spec ) {
97- beforeSpec(spec)
97+ beforeSpec.invoke (spec)
9898 }
9999
100100 override suspend fun afterSpec (spec : Spec ) {
101- afterSpec(spec)
101+ afterSpec.invoke (spec)
102102 if (mode == ContainerLifecycleMode .Spec && container.isRunning) close()
103103 }
104104
Original file line number Diff line number Diff line change @@ -11,14 +11,14 @@ private val container = GenericContainer("redis:5.0.3-alpine").apply {
1111 withExposedPorts(6379 )
1212}
1313
14- private val ext = SharedTestContainerExtension (container) {
15- JedisPool (container.host, container.firstMappedPort)
16- }
14+ private val ext = ContainerExtension (container)
1715
1816class SharedTestContainerExtensionTest1 : FunSpec () {
1917 init {
2018
21- val jedis = install(ext)
19+ val installed = install(ext)
20+ val jedis = JedisPool (installed.host, installed.firstMappedPort)
21+
2222
2323 test(" should be initialized in the spec" ) {
2424 jedis.resource.set(" foo" , " bar" )
@@ -34,7 +34,8 @@ class SharedTestContainerExtensionTest1 : FunSpec() {
3434class SharedTestContainerExtensionTest2 : FunSpec () {
3535 init {
3636
37- val jedis = install(ext)
37+ val installed = install(ext)
38+ val jedis = JedisPool (installed.host, installed.firstMappedPort)
3839
3940 test(" this spec should share the container" ) {
4041 jedis.resource.get(" foo" ) shouldBe " bar"
You can’t perform that action at this time.
0 commit comments