From 6511e4f24b80f34015a6770cc9e8e4a193f6b7c2 Mon Sep 17 00:00:00 2001 From: Marvin Froeder Date: Wed, 4 Dec 2024 19:08:35 -0300 Subject: [PATCH] Attempt to match event_time Signed-off-by: Marvin Froeder --- sqrl-calcite/pom.xml | 6 ++++++ .../java/com/datasqrl/util/SnapshotTest.java | 20 +++++++++++++++++-- .../com/datasqrl/FullUsecasesIT/loan_loan.txt | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/sqrl-calcite/pom.xml b/sqrl-calcite/pom.xml index 2dd70f687..82f27df4a 100644 --- a/sqrl-calcite/pom.xml +++ b/sqrl-calcite/pom.xml @@ -64,6 +64,12 @@ com.datasqrl sqrl-jdbc-1.19 + + org.assertj + assertj-core + 3.26.3 + test + diff --git a/sqrl-calcite/src/test/java/com/datasqrl/util/SnapshotTest.java b/sqrl-calcite/src/test/java/com/datasqrl/util/SnapshotTest.java index 0a9e04b5d..52df62279 100644 --- a/sqrl-calcite/src/test/java/com/datasqrl/util/SnapshotTest.java +++ b/sqrl-calcite/src/test/java/com/datasqrl/util/SnapshotTest.java @@ -4,6 +4,7 @@ package com.datasqrl.util; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.fail; import com.google.common.base.Preconditions; @@ -14,6 +15,7 @@ import java.util.Arrays; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import lombok.NonNull; import lombok.SneakyThrows; import lombok.Value; @@ -142,12 +144,26 @@ public void createOrValidate() { break; } } - assertEquals(expected, content, "Mismatched snapshots: " + fileName + " " + "file://"+path.toFile().getAbsolutePath()); + + if (expected.contains("***")) { + assertThat(content).matches(toRegex(expected)); + } else { + assertEquals(expected, content, "Mismatched snapshots: " + fileName + " " + "file://"+path.toFile().getAbsolutePath()); + } } } } - @SneakyThrows + private Pattern toRegex(String expectedContent) { + return Pattern.compile( + // Split on "***" + Arrays.stream(expectedContent.split("\\*\\*\\*")) + .map(Pattern::quote) // Quote each part for exact matching + .collect(Collectors.joining(".*")) + ); + } + + @SneakyThrows private boolean updateSnapshotProfile() { return Boolean.parseBoolean(System.getProperty("snapshots.update", "false")); } diff --git a/sqrl-testing/sqrl-integration-tests/src/test/resources/snapshots/com/datasqrl/FullUsecasesIT/loan_loan.txt b/sqrl-testing/sqrl-integration-tests/src/test/resources/snapshots/com/datasqrl/FullUsecasesIT/loan_loan.txt index 81518490f..b9fdfb14d 100644 --- a/sqrl-testing/sqrl-integration-tests/src/test/resources/snapshots/com/datasqrl/FullUsecasesIT/loan_loan.txt +++ b/sqrl-testing/sqrl-integration-tests/src/test/resources/snapshots/com/datasqrl/FullUsecasesIT/loan_loan.txt @@ -1,4 +1,4 @@ >>>applicationalert-subscription.graphql {"data":{"ApplicationAlert":[]}} >>>applicationupdate-mutation.graphql -{"data":{"ApplicationUpdates":{"loan_application_id":101,"message":"The road goes ever on and on"}}} +{"data":{"ApplicationUpdates":{"loan_application_id":101,"message":"The road goes ever on and on","event_time":"***"}}}