File tree 2 files changed +32
-4
lines changed
2 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -23,13 +23,13 @@ func NewLink(linkheader string) *Link {
23
23
link := & Link {}
24
24
links := strings .SplitN (linkheader , "," , 2 )
25
25
for _ , page := range links {
26
- data := strings .SplitN (page , ";" , 3 )
26
+ data := strings .SplitN (page , ";" , 4 )
27
27
28
- pagelink := strings .TrimLeft (data [0 ], "<" )
28
+ pagelink := strings .TrimLeft (strings . TrimSpace ( data [0 ]) , "<" )
29
29
pagelink = strings .TrimRight (pagelink , ">" )
30
30
31
- pagetype := strings .Trim (strings .Split (data [1 ], "=" )[1 ], " \" " )
32
- results , err := strconv .ParseBool (strings .Split (data [2 ], "=" )[1 ])
31
+ pagetype := strings .Trim (strings .Split (data [1 ], "=" )[1 ], `"` )
32
+ results , err := strconv .ParseBool (strings .Trim ( strings . Split (strings . TrimSpace ( data [2 ]) , "=" )[1 ], `"` ) )
33
33
if err != nil {
34
34
results = false
35
35
}
Original file line number Diff line number Diff line change
1
+ package sentry
2
+
3
+ import (
4
+ "testing"
5
+ )
6
+
7
+ func TestLinkPagination (t * testing.T ) {
8
+ examplelink := `<https://sentry.io/api/0/projects/the-interstellar-jurisdiction/pump-station/releases/?&cursor=100:-1:1>; rel="previous"; results="true"; cursor="100:-1:1", <https://sentry.io/api/0/projects/the-interstellar-jurisdiction/pump-station/releases/?&cursor=100:1:0>; rel="next"; results="true"; cursor="100:1:0`
9
+
10
+ link := NewLink (examplelink )
11
+
12
+ if link .Next .URL != "https://sentry.io/api/0/projects/the-interstellar-jurisdiction/pump-station/releases/?&cursor=100:1:0" {
13
+ t .Errorf ("Link next isnt correct: %s" , link .Next .URL )
14
+ }
15
+
16
+ if link .Previous .URL != "https://sentry.io/api/0/projects/the-interstellar-jurisdiction/pump-station/releases/?&cursor=100:-1:1" {
17
+ t .Errorf ("Link previous isnt correct: %s" , link .Previous .URL )
18
+ }
19
+
20
+ if ! link .Next .Results {
21
+ t .Error ("Results should be set to true for next" )
22
+ }
23
+
24
+ if ! link .Previous .Results {
25
+ t .Error ("Results should be set to true for previous" )
26
+ }
27
+
28
+ }
You can’t perform that action at this time.
0 commit comments