@@ -648,6 +648,35 @@ func TestResponse_populatePageValues(t *testing.T) {
648
648
}
649
649
}
650
650
651
+ func TestResponse_populateSinceValues (t * testing.T ) {
652
+ r := http.Response {
653
+ Header : http.Header {
654
+ "Link" : {`<https://api.github.com/?since=1>; rel="first",` +
655
+ ` <https://api.github.com/?since=2>; rel="prev",` +
656
+ ` <https://api.github.com/?since=4>; rel="next",` +
657
+ ` <https://api.github.com/?since=5>; rel="last"` ,
658
+ },
659
+ },
660
+ }
661
+
662
+ response := newResponse (& r )
663
+ if got , want := response .FirstPage , 1 ; got != want {
664
+ t .Errorf ("response.FirstPage: %v, want %v" , got , want )
665
+ }
666
+ if got , want := response .PrevPage , 2 ; want != got {
667
+ t .Errorf ("response.PrevPage: %v, want %v" , got , want )
668
+ }
669
+ if got , want := response .NextPage , 4 ; want != got {
670
+ t .Errorf ("response.NextPage: %v, want %v" , got , want )
671
+ }
672
+ if got , want := response .LastPage , 5 ; want != got {
673
+ t .Errorf ("response.LastPage: %v, want %v" , got , want )
674
+ }
675
+ if got , want := response .NextPageToken , "" ; want != got {
676
+ t .Errorf ("response.NextPageToken: %v, want %v" , got , want )
677
+ }
678
+ }
679
+
651
680
func TestResponse_cursorPagination (t * testing.T ) {
652
681
r := http.Response {
653
682
Header : http.Header {
@@ -761,6 +790,45 @@ func TestResponse_populatePageValues_invalid(t *testing.T) {
761
790
}
762
791
}
763
792
793
+ func TestResponse_populateSinceValues_invalid (t * testing.T ) {
794
+ r := http.Response {
795
+ Header : http.Header {
796
+ "Link" : {`<https://api.github.com/?since=1>,` +
797
+ `<https://api.github.com/?since=abc>; rel="first",` +
798
+ `https://api.github.com/?since=2; rel="prev",` +
799
+ `<https://api.github.com/>; rel="next",` +
800
+ `<https://api.github.com/?since=>; rel="last"` ,
801
+ },
802
+ },
803
+ }
804
+
805
+ response := newResponse (& r )
806
+ if got , want := response .FirstPage , 0 ; got != want {
807
+ t .Errorf ("response.FirstPage: %v, want %v" , got , want )
808
+ }
809
+ if got , want := response .PrevPage , 0 ; got != want {
810
+ t .Errorf ("response.PrevPage: %v, want %v" , got , want )
811
+ }
812
+ if got , want := response .NextPage , 0 ; got != want {
813
+ t .Errorf ("response.NextPage: %v, want %v" , got , want )
814
+ }
815
+ if got , want := response .LastPage , 0 ; got != want {
816
+ t .Errorf ("response.LastPage: %v, want %v" , got , want )
817
+ }
818
+
819
+ // more invalid URLs
820
+ r = http.Response {
821
+ Header : http.Header {
822
+ "Link" : {`<https://api.github.com/%?since=2>; rel="first"` },
823
+ },
824
+ }
825
+
826
+ response = newResponse (& r )
827
+ if got , want := response .FirstPage , 0 ; got != want {
828
+ t .Errorf ("response.FirstPage: %v, want %v" , got , want )
829
+ }
830
+ }
831
+
764
832
func TestDo (t * testing.T ) {
765
833
client , mux , _ , teardown := setup ()
766
834
defer teardown ()
0 commit comments