-
Notifications
You must be signed in to change notification settings - Fork 39
/
txnid_test.go
55 lines (52 loc) · 989 Bytes
/
txnid_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
45
46
47
48
49
50
51
52
53
54
55
package sync2
import "testing"
func TestTransactionIDCache(t *testing.T) {
alice := "@alice:localhost"
bob := "@bob:localhost"
eventA := "$a:localhost"
eventB := "$b:localhost"
eventC := "$c:localhost"
txn1 := "1"
txn2 := "2"
cache := NewTransactionIDCache()
cache.Store(alice, eventA, txn1)
cache.Store(bob, eventB, txn1) // different users can use same txn ID
cache.Store(alice, eventC, txn2)
testCases := []struct {
eventID string
userID string
want string
}{
{
eventID: eventA,
userID: alice,
want: txn1,
},
{
eventID: eventB,
userID: bob,
want: txn1,
},
{
eventID: eventC,
userID: alice,
want: txn2,
},
{
eventID: "$invalid",
userID: alice,
want: "",
},
{
eventID: eventA,
userID: "@invalid",
want: "",
},
}
for _, tc := range testCases {
txnID := cache.Get(tc.userID, tc.eventID)
if txnID != tc.want {
t.Errorf("%+v: got %v want %v", tc, txnID, tc.want)
}
}
}