Sometimes I need to install a port for Postgresql, which I run for tests in a container. But the Test container the developer command ofTestcontainers removed this feature. But somewhere there is a workaround solution, through the settings, but I can't find it. Who has any ideas or information on how to do this ?
public class ContainerConfig {
private static final PostgreSQLContainer postgresSQLContainer;
static {
DockerImageName postgres = DockerImageName.parse("postgres:13.1");
postgresSQLContainer = (PostgreSQLContainer) new PostgreSQLContainer(postgres)
.withDatabaseName("test")
.withUsername("root")
.withPassword("root")
.withReuse(true);
postgresSQLContainer.start();
}
@SuppressWarnings("rawtypes")
private static PostgreSQLContainer getPostgresSQLContainer() {
return postgresSQLContainer;
}
@SuppressWarnings("unused")
@DynamicPropertySource
public static void registerPgProperties(DynamicPropertyRegistry propertyRegistry) {
propertyRegistry.add("integration-tests-db", getPostgresSQLContainer()::getDatabaseName);
propertyRegistry.add("spring.datasource.username", getPostgresSQLContainer()::getUsername);
propertyRegistry.add("spring.datasource.password", getPostgresSQLContainer()::getPassword);
propertyRegistry.add("spring.datasource.url", getPostgresSQLContainer()::getJdbcUrl);
}
}