1
0
mirror of https://github.com/google/nomulus synced 2026-01-03 19:54:18 +00:00

Update golden schema comparison in schema test (#2805)

Postgresql-17.6 introduces two new lines in pg_dump output as a
security feature: `\restricted {HASH}` and `\unrestricted {HASH}`.

We filter out lines starting with these two prefixes when comparing
schemas.

The db upgrade also adds two empty lines to the pg_dump output. We
know ignore all empty lines when comparing schemas.
This commit is contained in:
Weimin Yu
2025-08-18 20:41:47 +00:00
committed by GitHub
parent d23640a54f
commit 1164070576
2 changed files with 6 additions and 4 deletions

View File

@@ -92,17 +92,19 @@ public class TextDiffSubject extends Subject {
private ImmutableList<String> filterComments(List<String> lines) { private ImmutableList<String> filterComments(List<String> lines) {
return lines.stream() return lines.stream()
.filter(line -> !line.isBlank())
.filter(line -> comments.stream().noneMatch(line::startsWith)) .filter(line -> comments.stream().noneMatch(line::startsWith))
.collect(ImmutableList.toImmutableList()); .collect(ImmutableList.toImmutableList());
} }
public void hasSameContentAs(List<String> expectedContent) { public void hasSameContentAs(List<String> expectedContent) {
checkNotNull(expectedContent, "expectedContent"); checkNotNull(expectedContent, "expectedContent");
ImmutableList<String> expected = filterComments(expectedContent); ImmutableList<String> filteredExpected = filterComments(expectedContent);
if (filterComments(expected).equals(filterComments(actual))) { ImmutableList<String> filteredActual = filterComments(actual);
if (filteredExpected.equals(filteredActual)) {
return; return;
} }
String diffString = diffFormat.generateDiff(expected, actual); String diffString = diffFormat.generateDiff(filteredExpected, filteredActual);
failWithoutActual( failWithoutActual(
Fact.simpleFact( Fact.simpleFact(
Joiner.on('\n') Joiner.on('\n')

View File

@@ -115,7 +115,7 @@ class SchemaTest {
Joiner.on(File.separatorChar).join(MOUNTED_RESOURCE_PATH, DUMP_OUTPUT_FILE)); Joiner.on(File.separatorChar).join(MOUNTED_RESOURCE_PATH, DUMP_OUTPUT_FILE));
assertThat(dumpedSchema) assertThat(dumpedSchema)
.ignoringLinesStartingWith("--") .ignoringLinesStartingWith("--", "\\restrict", "\\unrestrict")
.hasSameContentAs(Resources.getResource("sql/schema/nomulus.golden.sql")); .hasSameContentAs(Resources.getResource("sql/schema/nomulus.golden.sql"));
} }