Skip to content

Commit

Permalink
Attempt to match event_time
Browse files Browse the repository at this point in the history
Signed-off-by: Marvin Froeder <marvin@datasqrl.com>
  • Loading branch information
velo committed Dec 5, 2024
1 parent 14ddf39 commit fae1df4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions sqrl-calcite/src/test/java/com/datasqrl/util/SnapshotTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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;
Expand Down Expand Up @@ -129,7 +130,7 @@ public void createOrValidate() {
} else {
byte[] data = Files.readAllBytes(path);
String expected = new String(data);
if (!expected.equals(content)) {
if (!matchesExpectation(content, expected)) {
String[] expectedLines = expected.split("\n");
String[] contentLines = content.split("\n");
for (int i = 0; i < Math.min(expectedLines.length, contentLines.length); i++) {
Expand All @@ -142,11 +143,27 @@ public void createOrValidate() {
break;
}
}
assertEquals(expected, content, "Mismatched snapshots: " + fileName + " " + "file://"+path.toFile().getAbsolutePath());
assertEquals(expected, content, "Mismatched snapshots: " + fileName + " " + "file://" + path.toFile().getAbsolutePath());
}
}
}

private boolean matchesExpectation(String content, String expected) {
if (expected.contains("***")) {
return toRegex(expected).matcher(content).find();
}
return expected.equals(content);
}

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"));
Expand Down
Original file line number Diff line number Diff line change
@@ -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":"***"}}}

0 comments on commit fae1df4

Please sign in to comment.