aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/db.go1
-rw-r--r--test/event.go39
2 files changed, 40 insertions, 0 deletions
diff --git a/test/db.go b/test/db.go
index 9deec0a8..674fdf5c 100644
--- a/test/db.go
+++ b/test/db.go
@@ -121,6 +121,7 @@ func WithAllDatabases(t *testing.T, testFn func(t *testing.T, db DBType)) {
for dbName, dbType := range dbs {
dbt := dbType
t.Run(dbName, func(tt *testing.T) {
+ tt.Parallel()
testFn(tt, dbt)
})
}
diff --git a/test/event.go b/test/event.go
index 487b0936..b2e2805b 100644
--- a/test/event.go
+++ b/test/event.go
@@ -15,7 +15,9 @@
package test
import (
+ "bytes"
"crypto/ed25519"
+ "testing"
"time"
"github.com/matrix-org/gomatrixserverlib"
@@ -49,3 +51,40 @@ func WithUnsigned(unsigned interface{}) eventModifier {
e.unsigned = unsigned
}
}
+
+// Reverse a list of events
+func Reversed(in []*gomatrixserverlib.HeaderedEvent) []*gomatrixserverlib.HeaderedEvent {
+ out := make([]*gomatrixserverlib.HeaderedEvent, len(in))
+ for i := 0; i < len(in); i++ {
+ out[i] = in[len(in)-i-1]
+ }
+ return out
+}
+
+func AssertEventIDsEqual(t *testing.T, gotEventIDs []string, wants []*gomatrixserverlib.HeaderedEvent) {
+ t.Helper()
+ if len(gotEventIDs) != len(wants) {
+ t.Fatalf("length mismatch: got %d events, want %d", len(gotEventIDs), len(wants))
+ }
+ for i := range wants {
+ w := wants[i].EventID()
+ g := gotEventIDs[i]
+ if w != g {
+ t.Errorf("event at index %d mismatch:\ngot %s\n\nwant %s", i, string(g), string(w))
+ }
+ }
+}
+
+func AssertEventsEqual(t *testing.T, gots, wants []*gomatrixserverlib.HeaderedEvent) {
+ t.Helper()
+ if len(gots) != len(wants) {
+ t.Fatalf("length mismatch: got %d events, want %d", len(gots), len(wants))
+ }
+ for i := range wants {
+ w := wants[i].JSON()
+ g := gots[i].JSON()
+ if !bytes.Equal(w, g) {
+ t.Errorf("event at index %d mismatch:\ngot %s\n\nwant %s", i, string(g), string(w))
+ }
+ }
+}