Skip to content

Instantly share code, notes, and snippets.

@jamesdh
Created March 2, 2021 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesdh/0683d7c0fc91a938cf0f36dc18d20519 to your computer and use it in GitHub Desktop.
Save jamesdh/0683d7c0fc91a938cf0f36dc18d20519 to your computer and use it in GitHub Desktop.
Starting TestContainers and modifying config at startup in a Micronaut project
package com.example
import groovy.util.logging.Slf4j
import io.micronaut.test.support.TestPropertyProvider
import org.testcontainers.containers.GenericContainer
import org.testcontainers.utility.DockerImageName
import spock.lang.Specification
@Slf4j
abstract class IntegrationSpec extends Specification implements TestPropertyProvider {
static GenericContainer redisContainer = new GenericContainer(DockerImageName.parse("redis")).withExposedPorts(6379)
static {
redisContainer.start()
}
@Override
Map<String, String> getProperties() {
String redisUrl = "redis://${redisContainer.host}:${redisContainer.firstMappedPort}"
log.debug("Providing redis connection URL ${redisUrl}")
[
"redis.uri": redisUrl
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment