Skip to content
This repository was archived by the owner on Feb 16, 2025. It is now read-only.

Commit 080c8ef

Browse files
committed
Run the mount configure() hook before starting the container, so it can be configured in the hook.
Fixes #125
1 parent 9651962 commit 080c8ef

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/main/kotlin/io/kotest/extensions/testcontainers/ContainerExtension.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ class ContainerExtension<T : GenericContainer<*>>(
7373

7474
/**
7575
* Mounts the container, starting it if necessary. The [configure] block will be invoked
76-
* every time the container is mounted, and after the container has started.
76+
* every time the [ContainerExtension] is mounted, before the container is started.
7777
*/
7878
override fun mount(configure: T.() -> Unit): T = container.apply{
79+
configure()
80+
7981
if (!isRunning) {
8082
beforeStart()
8183
start()
8284
afterStart()
8385
}
84-
85-
configure()
8686
}
8787

8888
override suspend fun beforeTest(testCase: TestCase) {

src/test/kotlin/io/kotest/extensions/testcontainers/ContainerExtensionSpecLifecycleTest.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import com.redis.testcontainers.RedisContainer
44
import io.kotest.core.extensions.install
55
import io.kotest.core.spec.style.FunSpec
66
import io.kotest.matchers.shouldBe
7+
import org.testcontainers.containers.GenericContainer
78
import redis.clients.jedis.JedisPool
89

910
class ContainerExtensionSpecLifecycleTest : FunSpec() {
1011
init {
1112

12-
val container = install(ContainerExtension(RedisContainer("7.2.5-alpine"), ContainerLifecycleMode.Spec)) {
13+
// Using GenericContainer (which includes no out-of-the-box port mappings
14+
// to ensure the configure hook exposes ports correctly
15+
val container = install(ContainerExtension(GenericContainer("redis:7.2.5-alpine"), ContainerLifecycleMode.Spec)) {
1316
startupAttempts = 2
1417
withExposedPorts(6379)
1518
}

0 commit comments

Comments
 (0)