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 6511e4f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
6 changes: 6 additions & 0 deletions sqrl-calcite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
<groupId>com.datasqrl</groupId>
<artifactId>sqrl-jdbc-1.19</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.26.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
Expand Down
20 changes: 18 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 @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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"));
}
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 6511e4f

Please sign in to comment.