-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcursor_test.go
109 lines (106 loc) · 2.91 KB
/
cursor_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package filters
import (
"reflect"
"testing"
vocab "github.com/go-ap/activitypub"
)
func TestCursorFns(t *testing.T) {
tests := []struct {
name string
fns []Check
item vocab.Item
want vocab.Item
}{
{name: "empty"},
{
name: "just after",
fns: Checks{After(SameID("https://example.com"))},
item: vocab.ItemCollection{
vocab.Activity{ID: "https://example.com/1"},
vocab.Activity{ID: "https://example.com"},
vocab.Activity{ID: "https://example.com/2"},
},
want: vocab.ItemCollection{
vocab.Activity{ID: "https://example.com/2"},
},
},
{
name: "after with filters",
fns: Checks{After(SameID("example.com"), HasType("Activity"), After(SameID("example.com")))},
want: nil,
},
{
name: "maxItems=2 of 2",
fns: Checks{WithMaxCount(2)},
item: vocab.ItemCollection{
vocab.Activity{ID: "https://example.com/1"},
vocab.Activity{ID: "https://example.com/2"},
},
want: vocab.ItemCollection{
vocab.Activity{ID: "https://example.com/1"},
vocab.Activity{ID: "https://example.com/2"},
},
},
{
name: "maxItems=2 of 3",
fns: Checks{WithMaxCount(2)},
item: vocab.ItemCollection{
vocab.Activity{ID: "https://example.com/1"},
vocab.Activity{ID: "https://example.com/2"},
vocab.Activity{ID: "https://example.com/3"},
},
want: vocab.ItemCollection{
vocab.Activity{ID: "https://example.com/1"},
vocab.Activity{ID: "https://example.com/2"},
},
},
{
name: "before=https://example.com/1 single item",
fns: Checks{Before(SameID("https://example.com/1"))},
item: vocab.ItemCollection{
vocab.Activity{ID: "https://example.com/1"},
},
want: vocab.ItemCollection{},
},
{
name: "before=https://example.com/1 second item",
fns: Checks{Before(SameID("https://example.com/1"))},
item: vocab.ItemCollection{
vocab.Activity{ID: "https://example.com/0"},
vocab.Activity{ID: "https://example.com/1"},
vocab.Activity{ID: "https://example.com/2"},
},
want: vocab.ItemCollection{
vocab.Activity{ID: "https://example.com/0"},
},
},
{
name: "after=https://example.com/1 first item",
fns: Checks{After(SameID("https://example.com/1"))},
item: vocab.ItemCollection{
vocab.Activity{ID: "https://example.com/1"},
},
want: vocab.ItemCollection{},
},
{
name: "after=https://example.com/1 second item",
fns: Checks{After(SameID("https://example.com/1"))},
item: vocab.ItemCollection{
vocab.Activity{ID: "https://example.com/0"},
vocab.Activity{ID: "https://example.com/1"},
vocab.Activity{ID: "https://example.com/2"},
},
want: vocab.ItemCollection{
vocab.Activity{ID: "https://example.com/2"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotChecks := CursorChecks(tt.fns...)
if got := gotChecks.Run(tt.item); !reflect.DeepEqual(got, tt.want) {
t.Errorf("CursorChecks() = %v, want %v", got, tt.want)
}
})
}
}