-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpagination_test.go
37 lines (34 loc) · 1.05 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
package gopify
import (
"errors"
"testing"
)
func TestExtractPagination(t *testing.T) {
cases := []struct {
linkHeader string
expectedPagination *Pagination
expectedError error
}{
{
linkHeader: "invalid header",
expectedPagination: nil,
expectedError: errors.New("invalid header"),
},
{
linkHeader: `<https://resource.url?page_info=next_cursor>; rel="next"`,
expectedPagination: &Pagination{Next: "next_cursor"},
expectedError: nil,
},
{
linkHeader: `<https://resource.url?page_info=next_cursor>; rel="next", <http://resource.url?page_info=previous_cursor>; rel="previous"`,
expectedPagination: &Pagination{Next: "next_cursor", Previous: "previous_cursor"},
expectedError: nil,
},
}
for _, c := range cases {
pagination, err := extractPagination(c.linkHeader)
if pagination != c.expectedPagination && c.expectedError != err {
t.Errorf("expected pagination: %v, and error : %v, but got : %v, %v", c.expectedPagination, c.expectedError, pagination, err)
}
}
}