mirror of
https://github.com/google/nomulus
synced 2026-09-29 11:15:45 +00:00
Test database should use real locale configs (#3204)
Use the real locale configs from Cloud SQL when creating postgres database using docker.
This commit is contained in:
+5
@@ -139,6 +139,11 @@ public abstract class JpaTransactionManagerExtension
|
|||||||
private static JdbcDatabaseContainer<?> create() {
|
private static JdbcDatabaseContainer<?> create() {
|
||||||
PostgreSQLContainer<?> container =
|
PostgreSQLContainer<?> container =
|
||||||
new PostgreSQLContainer<>(NomulusPostgreSql.getDockerImageName())
|
new PostgreSQLContainer<>(NomulusPostgreSql.getDockerImageName())
|
||||||
|
// Locale configs in use on Cloud SQL in all environments
|
||||||
|
.withEnv(
|
||||||
|
"POSTGRES_INITDB_ARGS",
|
||||||
|
"--encoding=UTF8 --lc-collate=en_US.UTF8 --lc-ctype=en_US.UTF8"
|
||||||
|
+ " --locale-provider=libc --no-locale")
|
||||||
.withDatabaseName(POSTGRES_DB_NAME);
|
.withDatabaseName(POSTGRES_DB_NAME);
|
||||||
container.start();
|
container.start();
|
||||||
return container;
|
return container;
|
||||||
|
|||||||
+37
@@ -25,7 +25,10 @@ import google.registry.persistence.transaction.JpaTestExtensions.JpaUnitTestExte
|
|||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.PersistenceException;
|
import jakarta.persistence.PersistenceException;
|
||||||
|
import jakarta.persistence.Tuple;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
@@ -59,6 +62,40 @@ public class JpaTransactionManagerExtensionTest {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void verifyDatabaseEncodingConfig() {
|
||||||
|
String sql =
|
||||||
|
"""
|
||||||
|
SELECT
|
||||||
|
pg_encoding_to_char(encoding) AS encoding,
|
||||||
|
datcollate AS collation,
|
||||||
|
datctype AS ctype,
|
||||||
|
datlocprovider AS locale_provider,
|
||||||
|
datlocale AS locale
|
||||||
|
FROM
|
||||||
|
pg_database
|
||||||
|
WHERE
|
||||||
|
datname = 'postgres'
|
||||||
|
""";
|
||||||
|
List<Tuple> rows =
|
||||||
|
tm().transact(
|
||||||
|
() -> tm().getEntityManager().createNativeQuery(sql, Tuple.class).getResultList());
|
||||||
|
assertThat(rows).hasSize(1);
|
||||||
|
var row =
|
||||||
|
rows.get(0).getElements().stream()
|
||||||
|
.collect(
|
||||||
|
HashMap::new, // Use HashMap since there may be null value
|
||||||
|
(m, element) -> m.put(element.getAlias(), rows.get(0).get(element)),
|
||||||
|
Map::putAll);
|
||||||
|
assertThat(row)
|
||||||
|
.containsExactly(
|
||||||
|
"encoding", "UTF8",
|
||||||
|
"collation", "en_US.UTF8",
|
||||||
|
"ctype", "en_US.UTF8",
|
||||||
|
"locale_provider", 'c', // c --> libc
|
||||||
|
"locale", null);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testReplicaJpaTm() {
|
void testReplicaJpaTm() {
|
||||||
TestEntity testEntity = new TestEntity("foo", "bar");
|
TestEntity testEntity = new TestEntity("foo", "bar");
|
||||||
|
|||||||
Reference in New Issue
Block a user