diff --git a/common/src/testing/java/google/registry/testing/truth/TextDiffSubject.java b/common/src/testing/java/google/registry/testing/truth/TextDiffSubject.java index 43bd53f7a..894c92ff3 100644 --- a/common/src/testing/java/google/registry/testing/truth/TextDiffSubject.java +++ b/common/src/testing/java/google/registry/testing/truth/TextDiffSubject.java @@ -35,6 +35,7 @@ import com.google.common.truth.SimpleSubjectBuilder; import com.google.common.truth.Subject; import java.io.IOException; import java.net.URL; +import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; import java.util.List; @@ -63,6 +64,7 @@ public class TextDiffSubject extends Subject { private final ImmutableList actual; private DiffFormat diffFormat = DiffFormat.SIDE_BY_SIDE_MARKDOWN; + private List comments = new ArrayList<>(); protected TextDiffSubject(FailureMetadata metadata, List actual) { super(metadata, actual); @@ -83,10 +85,22 @@ public class TextDiffSubject extends Subject { return this; } + /** If set, ignore lines that start with the given string. */ + public TextDiffSubject ignoringLinesThatStartWith(String comment) { + comments.add(comment); + return this; + } + + private ImmutableList filterComments(List lines) { + return lines.stream() + .filter(line -> comments.stream().noneMatch(line::startsWith)) + .collect(ImmutableList.toImmutableList()); + } + public void hasSameContentAs(List expectedContent) { checkNotNull(expectedContent, "expectedContent"); - ImmutableList expected = ImmutableList.copyOf(expectedContent); - if (expected.equals(actual)) { + ImmutableList expected = filterComments(expectedContent); + if (filterComments(expected).equals(filterComments(actual))) { return; } String diffString = diffFormat.generateDiff(expected, actual); diff --git a/db/src/test/java/google/registry/sql/flyway/SchemaTest.java b/db/src/test/java/google/registry/sql/flyway/SchemaTest.java index 811884263..5a8bb133c 100644 --- a/db/src/test/java/google/registry/sql/flyway/SchemaTest.java +++ b/db/src/test/java/google/registry/sql/flyway/SchemaTest.java @@ -115,6 +115,7 @@ class SchemaTest { Joiner.on(File.separatorChar).join(MOUNTED_RESOURCE_PATH, DUMP_OUTPUT_FILE)); assertThat(dumpedSchema) + .ignoringLinesThatStartWith("--") .hasSameContentAs(Resources.getResource("sql/schema/nomulus.golden.sql")); }