Starting TestContainers and modifying config at startup in a Micronaut project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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