This repository was archived by the owner on Feb 16, 2025. It is now read-only.
File tree 2 files changed +10
-9
lines changed
main/kotlin/io/kotest/extensions/testcontainers
test/kotlin/io/kotest/extensions/testcontainers
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
53
53
* @param afterShutdown a callback that is invoked only once, just after the container is stopped.
54
54
* If the container is never started, this callback will not be invoked.
55
55
*/
56
- class ContainerExtension <T : GenericContainer <T >>(
56
+ class ContainerExtension <T : GenericContainer <* >>(
57
57
private val container : T ,
58
58
private val mode : ContainerLifecycleMode = ContainerLifecycleMode .Project ,
59
59
private val beforeStart : () -> Unit = {},
@@ -86,19 +86,19 @@ class ContainerExtension<T : GenericContainer<T>>(
86
86
}
87
87
88
88
override suspend fun beforeTest (testCase : TestCase ) {
89
- beforeTest(testCase)
89
+ beforeTest.invoke (testCase)
90
90
}
91
91
92
92
override suspend fun afterTest (testCase : TestCase , result : TestResult ) {
93
93
afterTest(testCase)
94
94
}
95
95
96
96
override suspend fun beforeSpec (spec : Spec ) {
97
- beforeSpec(spec)
97
+ beforeSpec.invoke (spec)
98
98
}
99
99
100
100
override suspend fun afterSpec (spec : Spec ) {
101
- afterSpec(spec)
101
+ afterSpec.invoke (spec)
102
102
if (mode == ContainerLifecycleMode .Spec && container.isRunning) close()
103
103
}
104
104
Original file line number Diff line number Diff line change @@ -11,14 +11,14 @@ private val container = GenericContainer("redis:5.0.3-alpine").apply {
11
11
withExposedPorts(6379 )
12
12
}
13
13
14
- private val ext = SharedTestContainerExtension (container) {
15
- JedisPool (container.host, container.firstMappedPort)
16
- }
14
+ private val ext = ContainerExtension (container)
17
15
18
16
class SharedTestContainerExtensionTest1 : FunSpec () {
19
17
init {
20
18
21
- val jedis = install(ext)
19
+ val installed = install(ext)
20
+ val jedis = JedisPool (installed.host, installed.firstMappedPort)
21
+
22
22
23
23
test(" should be initialized in the spec" ) {
24
24
jedis.resource.set(" foo" , " bar" )
@@ -34,7 +34,8 @@ class SharedTestContainerExtensionTest1 : FunSpec() {
34
34
class SharedTestContainerExtensionTest2 : FunSpec () {
35
35
init {
36
36
37
- val jedis = install(ext)
37
+ val installed = install(ext)
38
+ val jedis = JedisPool (installed.host, installed.firstMappedPort)
38
39
39
40
test(" this spec should share the container" ) {
40
41
jedis.resource.get(" foo" ) shouldBe " bar"
You can’t perform that action at this time.
0 commit comments