-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathtypes_internal_test.go
103 lines (99 loc) · 2.49 KB
/
types_internal_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
package stream
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestReadResponse_parseNext(t *testing.T) {
testCases := []struct {
next string
shouldError bool
err error
expected []GetActivitiesOption
}{
{
next: "",
shouldError: true,
err: ErrMissingNextPage,
},
{
next: "/test",
shouldError: true,
err: ErrInvalidNextPage,
},
{
next: "/test?k=%",
shouldError: true,
err: ErrInvalidNextPage,
},
{
next: "/test?limit=a",
shouldError: true,
err: fmt.Errorf(`strconv.Atoi: parsing "a": invalid syntax`),
},
{
next: "/test?offset=a",
shouldError: true,
err: fmt.Errorf(`strconv.Atoi: parsing "a": invalid syntax`),
},
{
next: "/test?limit=1&offset=2",
shouldError: false,
expected: []GetActivitiesOption{
WithActivitiesLimit(1),
WithActivitiesOffset(2),
},
},
{
next: "/test?limit=1&offset=2&id_lt=foo",
shouldError: false,
expected: []GetActivitiesOption{
WithActivitiesLimit(1),
WithActivitiesOffset(2),
WithActivitiesIDLT("foo"),
},
},
{
next: "/test?limit=1&offset=2&id_lt=foo&ranking=bar",
shouldError: false,
expected: []GetActivitiesOption{
WithActivitiesLimit(1),
WithActivitiesOffset(2),
WithActivitiesIDLT("foo"),
WithActivitiesRanking("bar"),
},
},
{
next: "/test?withOwnChildren=false&withRecentReactions=true&recentReactionsLimit=12&reactionKindsFilter=like,comment,upvote",
shouldError: false,
expected: []GetActivitiesOption{
WithEnrichRecentReactions(),
WithEnrichRecentReactionsLimit(12),
WithEnrichReactionKindsFilter("like", "comment", "upvote"),
},
},
{
next: "/test?withOwnChildren=true&withOwnChildrenKinds=like&withFirstReactions=true&reaction_limit=12&reactionKindsFilter=like,comment,upvote",
shouldError: false,
expected: []GetActivitiesOption{
WithEnrichFirstReactions(),
WithEnrichOwnChildren(),
WithEnrichReactionsLimit(12),
WithEnrichReactionKindsFilter("like", "comment", "upvote"),
WithEnrichOwnChildrenKindsFilter("like"),
},
},
}
for _, tc := range testCases {
r := readResponse{Next: tc.next}
opts, err := r.parseNext()
if tc.shouldError {
require.Error(t, err)
assert.Equal(t, tc.err.Error(), err.Error())
} else {
require.NoError(t, err)
assert.Equal(t, tc.expected, opts)
}
}
}