I am trying to implement an integration test for my Quarkus app where I use Test Container and Azurite to instantiate a blob container. Now when the container is started I can build the connection string using the port that the container is mapped to on my host.
The problem is that the Quarkus app is then already built and I’m having trouble updating the config property for the connection string.
Does anyone know how to do this?
@Singleton
public class BlobStorageTestResource implements QuarkusTestResourceLifecycleManager {
@Container
final GenericContainer azurite = new GenericContainer(DockerImageName.parse("mcr.microsoft.com/azure-storage/azurite"))
.withExposedPorts(10000)
.withCommand("azurite-blob --blobHost 0.0.0.0 --blobPort 10000 --loose");
@Override
public Map<String, String> start() {
azurite.start();
String connectionString = String.format("DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:%d/devstoreaccount1;", azurite.getFirstMappedPort());
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
.connectionString(connectionString)
.buildClient();
blobServiceClient.createBlobContainer("conversion");
return Map.of();
}
@Override
public void stop() {
azurite.stop();
}
}
@Produces
@Singleton
@IfBuildProfile("test")
BlobContainerAsyncClient provideTestBlobContainer() {
return new BlobServiceClientBuilder()
.connectionString(blobConfig.connectionString())
.buildAsyncClient()
.getBlobContainerAsyncClient(blobConfig.containerName());
}