-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
pagination_test.go
51 lines (44 loc) · 1.46 KB
/
pagination_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
package desec
import (
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
func Test_parseCursor(t *testing.T) {
testCases := []struct {
desc string
header string
expected *Cursors
}{
{
desc: "all cursors",
header: `<https://desec.io/api/v1/domains/{domain}/rrsets/?cursor=>; rel="first", <https://desec.io/api/v1/domains/{domain}/rrsets/?cursor=:prev_cursor>; rel="prev", <https://desec.io/api/v1/domains/{domain}/rrsets/?cursor=:next_cursor>; rel="next"`,
expected: &Cursors{First: "", Prev: ":prev_cursor", Next: ":next_cursor"},
},
{
desc: "first page",
header: `<https://desec.io/api/v1/domains/{domain}/rrsets/?cursor=>; rel="first", <https://desec.io/api/v1/domains/{domain}/rrsets/?cursor=:next_cursor>; rel="next"`,
expected: &Cursors{First: "", Prev: "", Next: ":next_cursor"},
},
{
desc: "last page",
header: `<https://desec.io/api/v1/domains/{domain}/rrsets/?cursor=>; rel="first", <https://desec.io/api/v1/domains/{domain}/rrsets/?cursor=:prev_cursor>; rel="prev"`,
expected: &Cursors{First: "", Prev: ":prev_cursor", Next: ""},
},
{
desc: "empty",
header: ``,
expected: &Cursors{First: "", Prev: "", Next: ""},
},
}
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
h := http.Header{}
h.Set("Link", test.header)
cursor, err := parseCursor(h)
require.NoError(t, err)
require.Equal(t, test.expected, cursor)
})
}
}