Require explict tag when starting psql docker (#368)

* Require explict tag when starting psql docker

Defined a util class to return docker tag of desired PSQL version.
Class is defined in ':db' and shared by ':db' and ':core'. Used
an artifact declaration to exclude unnecesary compile dependencies.

Added a presubmit check for instantiations without explicit tag.
This commit is contained in:
Weimin Yu 2019-11-18 11:33:26 -05:00 committed by GitHub
parent 2cc2571375
commit 365c5da942
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 69 additions and 7 deletions

View file

@ -25,6 +25,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.io.Resources;
import google.registry.persistence.HibernateSchemaExporter;
import google.registry.persistence.NomulusPostgreSql;
import google.registry.persistence.PersistenceModule;
import google.registry.persistence.PersistenceXmlUtility;
import google.registry.testing.FakeClock;
@ -90,7 +91,9 @@ public class JpaTransactionManagerRule extends ExternalResource {
}
private static JdbcDatabaseContainer create() {
PostgreSQLContainer container = new PostgreSQLContainer().withDatabaseName(MANAGEMENT_DB_NAME);
PostgreSQLContainer container =
new PostgreSQLContainer(NomulusPostgreSql.getDockerTag())
.withDatabaseName(MANAGEMENT_DB_NAME);
container.start();
Runtime.getRuntime().addShutdownHook(new Thread(() -> container.close()));
return container;

View file

@ -36,7 +36,10 @@ import org.testcontainers.containers.PostgreSQLContainer;
/** Unit tests for {@link HibernateSchemaExporter}. */
@RunWith(JUnit4.class)
public class HibernateSchemaExporterTest {
@ClassRule public static final PostgreSQLContainer database = new PostgreSQLContainer();
@ClassRule
public static final PostgreSQLContainer database =
new PostgreSQLContainer(NomulusPostgreSql.getDockerTag());
private static HibernateSchemaExporter exporter;
@Rule public final TemporaryFolder tempFolder = new TemporaryFolder();

View file

@ -29,7 +29,8 @@ import org.testcontainers.containers.PostgreSQLContainer;
/** Unit tests for {@link PersistenceModule}. */
@RunWith(JUnit4.class)
public class PersistenceModuleTest {
@Rule public PostgreSQLContainer database = new PostgreSQLContainer();
@Rule
public PostgreSQLContainer database = new PostgreSQLContainer(NomulusPostgreSql.getDockerTag());
private EntityManagerFactory emf;

View file

@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.io.Files;
import google.registry.persistence.NomulusPostgreSql;
import java.io.File;
import org.junit.Before;
import org.junit.ClassRule;
@ -37,8 +38,9 @@ public class GenerateSqlSchemaCommandTest extends CommandTestCase<GenerateSqlSch
@Rule public TemporaryFolder tmp = new TemporaryFolder();
@ClassRule public static PostgreSQLContainer postgres =
new PostgreSQLContainer()
@ClassRule
public static PostgreSQLContainer postgres =
new PostgreSQLContainer(NomulusPostgreSql.getDockerTag())
.withDatabaseName("postgres")
.withUsername("postgres")
.withPassword("domain-registry");