@@ -12,6 +12,17 @@ import (
12
12
dsq "github.com/ipfs/go-datastore/query"
13
13
)
14
14
15
+ // ElemCount sets with how many elements the datastore suit
16
+ // tests are usually run with. Best to set to round numbers like
17
+ // 20, 30, 40... and at least to 20.
18
+ var ElemCount = 100
19
+
20
+ func TestElemCount (t * testing.T ) {
21
+ if ElemCount < 20 {
22
+ t .Fatal ("ElemCount should be set to 20 at least" )
23
+ }
24
+ }
25
+
15
26
func SubtestBasicPutGet (t * testing.T , ds dstore.Datastore ) {
16
27
k := dstore .NewKey ("foo" )
17
28
val := []byte ("Hello Datastore!" )
@@ -132,20 +143,20 @@ func SubtestLimit(t *testing.T, ds dstore.Datastore) {
132
143
Offset : offset ,
133
144
Limit : limit ,
134
145
KeysOnly : true ,
135
- }, 100 )
146
+ }, ElemCount )
136
147
})
137
148
}
138
- test (0 , 10 )
149
+ test (0 , ElemCount / 10 )
139
150
test (0 , 0 )
140
- test (10 , 0 )
141
- test (10 , 10 )
142
- test (10 , 20 )
143
- test (50 , 20 )
144
- test (99 , 20 )
145
- test (200 , 20 )
146
- test (200 , 0 )
147
- test (99 , 0 )
148
- test (95 , 0 )
151
+ test (ElemCount / 10 , 0 )
152
+ test (ElemCount / 10 , ElemCount / 10 )
153
+ test (ElemCount / 10 , ElemCount / 5 )
154
+ test (ElemCount / 2 , ElemCount / 5 )
155
+ test (ElemCount - 1 , ElemCount / 5 )
156
+ test (ElemCount * 2 , ElemCount / 5 )
157
+ test (ElemCount * 2 , 0 )
158
+ test (ElemCount - 1 , 0 )
159
+ test (ElemCount - 5 , 0 )
149
160
}
150
161
151
162
func SubtestOrder (t * testing.T , ds dstore.Datastore ) {
@@ -158,7 +169,7 @@ func SubtestOrder(t *testing.T, ds dstore.Datastore) {
158
169
t .Run (name , func (t * testing.T ) {
159
170
subtestQuery (t , ds , dsq.Query {
160
171
Orders : orders ,
161
- }, 100 )
172
+ }, ElemCount )
162
173
})
163
174
}
164
175
test (dsq.OrderByKey {})
@@ -173,7 +184,7 @@ func SubtestOrder(t *testing.T, ds dstore.Datastore) {
173
184
}
174
185
175
186
func SubtestManyKeysAndQuery (t * testing.T , ds dstore.Datastore ) {
176
- subtestQuery (t , ds , dsq.Query {KeysOnly : true }, 100 )
187
+ subtestQuery (t , ds , dsq.Query {KeysOnly : true }, ElemCount )
177
188
}
178
189
179
190
func SubtestBasicSync (t * testing.T , ds dstore.Datastore ) {
@@ -217,15 +228,15 @@ func (testFilter) Filter(e dsq.Entry) bool {
217
228
func SubtestCombinations (t * testing.T , ds dstore.Datastore ) {
218
229
offsets := []int {
219
230
0 ,
220
- 10 ,
221
- 95 ,
222
- 100 ,
231
+ ElemCount / 10 ,
232
+ ElemCount - 5 ,
233
+ ElemCount ,
223
234
}
224
235
limits := []int {
225
236
0 ,
226
237
1 ,
227
- 10 ,
228
- 100 ,
238
+ ElemCount / 10 ,
239
+ ElemCount ,
229
240
}
230
241
filters := [][]dsq.Filter {
231
242
{dsq.FilterKeyCompare {
@@ -251,7 +262,7 @@ func SubtestCombinations(t *testing.T, ds dstore.Datastore) {
251
262
lengths := []int {
252
263
0 ,
253
264
1 ,
254
- 100 ,
265
+ ElemCount / 10 ,
255
266
}
256
267
perms (
257
268
func (perm []int ) {
@@ -347,7 +358,7 @@ func SubtestPrefix(t *testing.T, ds dstore.Datastore) {
347
358
t .Run (prefix , func (t * testing.T ) {
348
359
subtestQuery (t , ds , dsq.Query {
349
360
Prefix : prefix ,
350
- }, 100 )
361
+ }, ElemCount )
351
362
})
352
363
}
353
364
test ("" )
0 commit comments