@@ -2,11 +2,13 @@ package query
22
33import (
44 "testing"
5+
6+ "github.com/stretchr/testify/assert"
57)
68
79func TestParsePagination (t * testing.T ) {
810 // invalid limit
9- _ , err := ParsePagination ("1s" , "0" , "ptoken" )
11+ _ , err := ParsePagination ("1s" , "0" , "ptoken" , "" )
1012 if err == nil {
1113 t .Error ("unexpected nil error - expected: pagination: limit - invalid syntax" )
1214 }
@@ -15,7 +17,7 @@ func TestParsePagination(t *testing.T) {
1517 }
1618
1719 // negative limit
18- _ , err = ParsePagination ("-1" , "0" , "ptoken" )
20+ _ , err = ParsePagination ("-1" , "0" , "ptoken" , "" )
1921 if err == nil {
2022 t .Error ("unexpected nil error - expected: pagination: limit must be a positive value" )
2123 }
@@ -24,7 +26,7 @@ func TestParsePagination(t *testing.T) {
2426 }
2527
2628 // zero limit
27- _ , err = ParsePagination ("0" , "0" , "ptoken" )
29+ _ , err = ParsePagination ("0" , "0" , "ptoken" , "" )
2830 if err == nil {
2931 t .Error ("unexpected nil error - expected: pagination: limit must be a positive value" )
3032 }
@@ -33,7 +35,7 @@ func TestParsePagination(t *testing.T) {
3335 }
3436
3537 // invalid offset
36- _ , err = ParsePagination ("" , "0w" , "ptoken" )
38+ _ , err = ParsePagination ("" , "0w" , "ptoken" , "" )
3739 if err == nil {
3840 t .Error ("unexpected nil error - expected: pagination: offset - invalid syntax" )
3941 }
@@ -42,7 +44,7 @@ func TestParsePagination(t *testing.T) {
4244 }
4345
4446 // negative offset
45- _ , err = ParsePagination ("" , "-1" , "ptoken" )
47+ _ , err = ParsePagination ("" , "-1" , "ptoken" , "" )
4648 if err == nil {
4749 t .Error ("unexpected nil error - expected: pagination: offset - negative value" )
4850 }
@@ -51,7 +53,7 @@ func TestParsePagination(t *testing.T) {
5153 }
5254
5355 // null offset
54- p , err := ParsePagination ("" , "null" , "ptoken" )
56+ p , err := ParsePagination ("" , "null" , "ptoken" , "" )
5557 if err != nil {
5658 t .Errorf ("unexpected error: %v" , err )
5759 }
@@ -60,14 +62,14 @@ func TestParsePagination(t *testing.T) {
6062 }
6163
6264 // first page
63- p , err = ParsePagination ("" , "0" , "ptoken" )
65+ p , err = ParsePagination ("" , "0" , "ptoken" , "" )
6466 if err != nil {
6567 t .Errorf ("unexpected error: %s" , err )
6668 }
6769 if ! p .FirstPage () {
6870 t .Errorf ("invalid value of first page: %v - expected: true" , p .FirstPage ())
6971 }
70- p , err = ParsePagination ("" , "100" , "null" )
72+ p , err = ParsePagination ("" , "100" , "null" , "" )
7173 if err != nil {
7274 t .Errorf ("unexpected error: %s" , err )
7375 }
@@ -81,7 +83,7 @@ func TestParsePagination(t *testing.T) {
8183 }
8284
8385 // valid pagination
84- p , err = ParsePagination ("1000" , "100" , "ptoken" )
86+ p , err = ParsePagination ("1000" , "100" , "ptoken" , "" )
8587 if err != nil {
8688 t .Errorf ("unexpected error: %s" , err )
8789 }
@@ -94,6 +96,30 @@ func TestParsePagination(t *testing.T) {
9496 if p .GetPageToken () != "ptoken" {
9597 t .Errorf ("invalid page token: %q - expected: ptoken" , p .GetPageToken ())
9698 }
99+
100+ // valid pagination with isTotalSizeNeeded=true
101+ p , err = ParsePagination ("1000" , "100" , "ptoken" , "true" )
102+ if err != nil {
103+ t .Errorf ("unexpected error: %s" , err )
104+ }
105+ assert .Equal (t , true , p .GetIsTotalSizeNeeded ())
106+
107+ // valid pagination with isTotalSizeNeeded=false
108+ p , err = ParsePagination ("1000" , "100" , "ptoken" , "false" )
109+ if err != nil {
110+ t .Errorf ("unexpected error: %s" , err )
111+ }
112+ assert .Equal (t , false , p .GetIsTotalSizeNeeded ())
113+
114+ // valid pagination with isTotalSizeNeeded=null
115+ _ , err = ParsePagination ("1000" , "100" , "ptoken" , "null" )
116+ if err == nil {
117+ t .Error ("unexpected nil error - expected: pagination: is_total_size_needed - invalid syntax" )
118+ }
119+ if err .Error () != "pagination: is_total_size_needed - invalid syntax" {
120+ t .Errorf ("invalid error: %s - expected: pagination: is_total_size_needed - invalid syntax" , err )
121+ }
122+
97123}
98124
99125func TestPageInfo (t * testing.T ) {
0 commit comments