@@ -13,7 +13,11 @@ import (
13
13
)
14
14
15
15
func TestBatchCursor (t * testing.T ) {
16
+ t .Parallel ()
17
+
16
18
t .Run ("setBatchSize" , func (t * testing.T ) {
19
+ t .Parallel ()
20
+
17
21
var size int32
18
22
bc := & BatchCursor {
19
23
batchSize : size ,
@@ -24,4 +28,65 @@ func TestBatchCursor(t *testing.T) {
24
28
bc .SetBatchSize (size )
25
29
assert .Equal (t , size , bc .batchSize , "expected batchSize %v, got %v" , size , bc .batchSize )
26
30
})
31
+
32
+ t .Run ("calcGetMoreBatchSize" , func (t * testing.T ) {
33
+ t .Parallel ()
34
+
35
+ for _ , tcase := range []struct {
36
+ name string
37
+ size , limit , numReturned , expected int32
38
+ ok bool
39
+ }{
40
+ {
41
+ name : "empty" ,
42
+ expected : 0 ,
43
+ ok : true ,
44
+ },
45
+ {
46
+ name : "batchSize NEQ 0" ,
47
+ size : 4 ,
48
+ expected : 4 ,
49
+ ok : true ,
50
+ },
51
+ {
52
+ name : "limit NEQ 0" ,
53
+ limit : 4 ,
54
+ expected : 0 ,
55
+ ok : true ,
56
+ },
57
+ {
58
+ name : "limit NEQ and batchSize + numReturned EQ limit" ,
59
+ size : 4 ,
60
+ limit : 8 ,
61
+ numReturned : 4 ,
62
+ expected : 4 ,
63
+ ok : true ,
64
+ },
65
+ {
66
+ name : "limit makes batchSize negative" ,
67
+ numReturned : 4 ,
68
+ limit : 2 ,
69
+ expected : - 2 ,
70
+ ok : false ,
71
+ },
72
+ } {
73
+ tcase := tcase
74
+ t .Run (tcase .name , func (t * testing.T ) {
75
+ t .Parallel ()
76
+
77
+ bc := & BatchCursor {
78
+ limit : tcase .limit ,
79
+ batchSize : tcase .size ,
80
+ numReturned : tcase .numReturned ,
81
+ }
82
+
83
+ bc .SetBatchSize (tcase .size )
84
+
85
+ size , ok := calcGetMoreBatchSize (* bc )
86
+
87
+ assert .Equal (t , tcase .expected , size , "expected batchSize %v, got %v" , tcase .expected , size )
88
+ assert .Equal (t , tcase .ok , ok , "expected ok %v, got %v" , tcase .ok , ok )
89
+ })
90
+ }
91
+ })
27
92
}
0 commit comments