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

Commit 223a2c2

Browse files
committed
Fixed type inference on DockerComposeContainerExtension
1 parent 332c79f commit 223a2c2

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import kotlinx.coroutines.Dispatchers
1313
import kotlinx.coroutines.withContext
1414
import org.testcontainers.containers.DockerComposeContainer
1515
import org.testcontainers.containers.GenericContainer
16+
import java.io.File
1617

1718
/**
1819
* A Kotest [MountableExtension] for [GenericContainer]s that are started the first time they are
@@ -47,7 +48,7 @@ import org.testcontainers.containers.GenericContainer
4748
* @param afterShutdown a callback that is invoked only once, just after the container is stopped.
4849
* If the container is never started, this callback will not be invoked.
4950
*/
50-
class DockerComposeContainerExtension<T : DockerComposeContainer<T>>(
51+
class DockerComposeContainerExtension<T : DockerComposeContainer<out T>>(
5152
private val container: T,
5253
private val mode: ContainerLifecycleMode = ContainerLifecycleMode.Project,
5354
private val beforeStart: (T) -> Unit = {},
@@ -65,6 +66,17 @@ class DockerComposeContainerExtension<T : DockerComposeContainer<T>>(
6566
AfterTestListener,
6667
AfterSpecListener {
6768

69+
companion object {
70+
operator fun invoke(composeFile: File): DockerComposeContainerExtension<DockerComposeContainer<Nothing>> =
71+
DockerComposeContainerExtension(DockerComposeContainer<Nothing>(composeFile))
72+
73+
operator fun invoke(
74+
composeFile: File,
75+
mode: ContainerLifecycleMode = ContainerLifecycleMode.Project,
76+
): DockerComposeContainerExtension<DockerComposeContainer<Nothing>> =
77+
DockerComposeContainerExtension(DockerComposeContainer<Nothing>(composeFile), mode)
78+
}
79+
6880
private var started: Boolean = false
6981

7082
/**
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.kotest.extensions.testcontainers
2+
3+
import io.kotest.core.extensions.install
4+
import io.kotest.core.spec.style.StringSpec
5+
import io.kotest.matchers.optional.shouldBePresent
6+
import io.kotest.matchers.string.shouldContain
7+
import org.testcontainers.containers.DockerComposeContainer
8+
import java.io.File
9+
10+
class DockerComposeContainerExtensionTest : StringSpec() {
11+
init {
12+
13+
val container: DockerComposeContainer<Nothing> =
14+
install(DockerComposeContainerExtension(File("src/test/resources/docker-compose/docker-compose.yml")))
15+
16+
"should setup using docker-compose" {
17+
container.getContainerByServiceName("hello_world").shouldBePresent().logs shouldContain "Hello world"
18+
}
19+
}
20+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.testcontainers.containers.KafkaContainer
1111
import org.testcontainers.utility.DockerImageName
1212
import java.time.Duration
1313

14+
@Deprecated("To be removed")
1415
class KafkaTestContainerExtensionTest : FunSpec() {
1516
init {
1617

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import io.kotest.core.spec.style.StringSpec
44
import io.kotest.matchers.collections.shouldHaveSize
55

66
class StartableTestLifecycleAwareTest : StringSpec({
7+
78
val startableTestLifecycleAwareForPerTest = StartableTestLifecycleAware()
89
val startableTestLifecycleAwareForPerSpec = StartableTestLifecycleAware()
910

0 commit comments

Comments
 (0)