Я установил свой тестовый ресурс >
Код: Выделить всё
@Slf4j
public class PostgreSQLTestResource implements QuarkusTestResourceLifecycleManager {
private static PostgreSQLContainer postgreSQLContainer;
@Override
public Map start() {
log.info("Starting PostgreSQL with profile: {}", System.getProperty("quarkus.profile"));
postgreSQLContainer =
new PostgreSQLContainer("postgres:alpine")
.withDatabaseName("test")
.withUsername("postgres")
.withPassword("password")
.withReuse(true);
postgreSQLContainer.start();
Map config = new HashMap();
config.put("quarkus.datasource.jdbc.url", postgreSQLContainer.getJdbcUrl());
config.put("quarkus.datasource.username", postgreSQLContainer.getUsername());
config.put("quarkus.datasource.password", postgreSQLContainer.getPassword());
config.put("quarkus.liquibase.jdbc.url", postgreSQLContainer.getJdbcUrl());
log.info("JDBC URL: {}", postgreSQLContainer.getJdbcUrl());
return config;
}
@Override
public void stop() {
if (postgreSQLContainer != null) {
postgreSQLContainer.stop();
}
}
}
Код: Выделить всё
@QuarkusTest
@TestProfile(TestProfileResolver.class)
@QuarkusTestResource(value = PostgreSQLTestResource.class,restrictToAnnotatedClass = true)
public class XServiceTest {
@Inject
XTypeVersionService xTypeVersionService;
@BeforeEach
void setUp() {
closeable = MockitoAnnotations.openMocks(this);
}
@AfterEach
void closeMocks() throws Exception {
closeable.close();
}
...
@Test
void getXTypeVersion() {
List guh = xTypeVersionService.get();
assertTrue(!guh.isEmpty());
}
}
And
public class TestProfileResolver implements QuarkusTestProfile {
@Override
public String getConfigProfile() {
String activeProfile = System.getProperty("quarkus.profile");
log.info("Active profile: {}", activeProfile);
return "test";
}
@Override
public Map getConfigOverrides() {
String configLocation = System.getProperty("quarkus.config.locations");
log.info("Config location: {}", configLocation);
if (configLocation == null || configLocation.isEmpty()) {
log.info("Setting config location to src/test/resources/application.yaml");
return Map.of("quarkus.config.locations", "src/test/resources/application.yaml");
}
return Collections.emptyMap();
}
}
Код: Выделить всё
quarkus:
profile: test
http:
test-port: 9300
datasource:
db-kind: postgresql
jdbc:
url: jdbc:tc:postgresql:alpine://test?TC_INITSCRIPT=init.sql
driver: org.testcontainers.jdbc.ContainerDatabaseDriver
hibernate-orm:
database:
generation: drop-and-create
liquibase:
enabled: true
migrate-at-start: true
change-log: classpath:db/dbChangelog-test.yaml
default-schema-name: x
validate-on-migrate: true
jdbc-url: jdbc:tc:postgresql:alpine://test?TC_INITSCRIPT=init.sql
log:
min-level: DEBUG
category:
"io.quarkus":
level: INFO
"org.testcontainers":
level: INFO
"liquibase":
level: TRACE
Я считаю, что сценарий Liquibase выполняется в одном контейнере, а приложение обращается ко второму.
Была ли у кого-нибудь подобная проблема или, что еще лучше, рабочий пример тестовых контейнеров с Liquibase (а еще лучше с использованием Quarkus)?
Подробнее здесь: https://stackoverflow.com/questions/792 ... -liquibase