Skip to content

Instantly share code, notes, and snippets.

@iainporter
Created July 17, 2020 18:26
Show Gist options
  • Save iainporter/04dcf2bb8564df22f9308a5e73151c90 to your computer and use it in GitHub Desktop.
Save iainporter/04dcf2bb8564df22f9308a5e73151c90 to your computer and use it in GitHub Desktop.
Base class for component tests
abstract class TestEnvironment {
@Before
fun setup() {
val port = env.getServicePort("sms-service_1", 8080)
RestAssured.baseURI = "http://localhost:$port"
}
companion object {
val env: KDockerComposeContainer by lazy {initDockerCompose()}
class KDockerComposeContainer(path: File) : DockerComposeContainer<KDockerComposeContainer>(path)
private fun initDockerCompose() = KDockerComposeContainer(File("src/test/resources/docker-compose.yml"))
.withExposedService("sms-service_1", 8080)
.withExposedService("postgres-db_1", 5432)
.waitingFor("sms-service", Wait.forHttp("/health"))
init {
env.start()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment