forked from matrix-org/gomatrixserverlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstateresolution_test.go
44 lines (40 loc) · 1.19 KB
/
stateresolution_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package gomatrixserverlib
import (
"testing"
)
const (
sha1OfEventID1A = "\xe5\x89,\xa2\x1cF<&\xf3\rf}\xde\xa5\xef;\xddK\xaaS"
sha1OfEventID2A = "\xa4\xe4\x10\x1b}\x1a\xf9`\x94\x10\xa3\x84+\xae\x06\x8d\x16A\xfc>"
sha1OfEventID3B = "\xca\xe8\xde\xb6\xa3\xb6\xee\x01\xc4\xbc\xd0/\x1b\x1c2\x0c\xd3\xa4\xe9\xcb"
)
func TestConflictEventSorter(t *testing.T) {
var f1, f2, f3 eventFormatV1Fields
f1.EventID = "@1:a"
f2.EventID = "@2:a"
f3.EventID = "@3:b"
f1.Depth = 1
f2.Depth = 2
f3.Depth = 2
input := []*Event{
{roomVersion: RoomVersionV1, fields: f1},
{roomVersion: RoomVersionV1, fields: f2},
{roomVersion: RoomVersionV1, fields: f3},
}
got := sortConflictedEventsByDepthAndSHA1(input)
want := []conflictedEvent{
{depth: 1, event: input[0]},
{depth: 2, event: input[2]},
{depth: 2, event: input[1]},
}
copy(want[0].eventIDSHA1[:], sha1OfEventID1A)
copy(want[1].eventIDSHA1[:], sha1OfEventID3B)
copy(want[2].eventIDSHA1[:], sha1OfEventID2A)
if len(want) != len(got) {
t.Fatalf("Different length: wanted %d, got %d", len(want), len(got))
}
for i := range want {
if want[i] != got[i] {
t.Fatalf("Different element at index %d: wanted %#v got %#v", i, want[i], got[i])
}
}
}