Achoday
Achoday

Reputation: 1

Quarkus environment variables issue with Test containers

Developed the integration tests using Test container. Have few fields as environment variables(Eg: passing it as quarkus.datasource.username=${SER_DB_USERNAME:postgres}) in application.properties file.

When setting environment field through test container

GenericContainer<?> someService = new GenericContainer<>(img)
 .withEnv("SER_DB_USERNAME", DataLayer.DB_USERNAME)

This value is being successfully taken with test containers but

For the below environment variable, app.security.enabled=${SER_SEC_ENABLE:true} defined in application.properties file

@IfBuildProperty(name = "app.security.enabled", stringValue = "true")

the environment variable is setting through cmd prompt using -DSER_SEC_ENABLED=true, but when trying to pass the same value in test containers, it's always null.

GenericContainer<?> someService = new GenericContainer<>(img)
.withEnv("SER_SEC_ENABLE", "true")

Upvotes: 0

Views: 1439

Answers (1)

Kevin Wittek
Kevin Wittek

Reputation: 1602

Without having more context of the project, I can at least observe, that app.security.enabled is a build property rather than a runtime property, so it might be evaluated at build time already. If you start the container with an already built image/application, it is very likely, that the environment variable has no effect.

Furthermore, setting a property on the JVM using the -D flag does not result in an environment variable, this is explicitly a system property on the JVM.

Upvotes: 0

Related Questions