Skip to content

Commit b8e7d93

Browse files
authored
Merge pull request #151 from ipfs/feat/set-count
test suite: Add ElemCount to control how many elements are added.
2 parents d099e8e + d72bbd3 commit b8e7d93

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

test/basic_tests.go

+31-20
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ import (
1212
dsq "github.com/ipfs/go-datastore/query"
1313
)
1414

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+
1526
func SubtestBasicPutGet(t *testing.T, ds dstore.Datastore) {
1627
k := dstore.NewKey("foo")
1728
val := []byte("Hello Datastore!")
@@ -132,20 +143,20 @@ func SubtestLimit(t *testing.T, ds dstore.Datastore) {
132143
Offset: offset,
133144
Limit: limit,
134145
KeysOnly: true,
135-
}, 100)
146+
}, ElemCount)
136147
})
137148
}
138-
test(0, 10)
149+
test(0, ElemCount/10)
139150
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)
149160
}
150161

151162
func SubtestOrder(t *testing.T, ds dstore.Datastore) {
@@ -158,7 +169,7 @@ func SubtestOrder(t *testing.T, ds dstore.Datastore) {
158169
t.Run(name, func(t *testing.T) {
159170
subtestQuery(t, ds, dsq.Query{
160171
Orders: orders,
161-
}, 100)
172+
}, ElemCount)
162173
})
163174
}
164175
test(dsq.OrderByKey{})
@@ -173,7 +184,7 @@ func SubtestOrder(t *testing.T, ds dstore.Datastore) {
173184
}
174185

175186
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)
177188
}
178189

179190
func SubtestBasicSync(t *testing.T, ds dstore.Datastore) {
@@ -217,15 +228,15 @@ func (testFilter) Filter(e dsq.Entry) bool {
217228
func SubtestCombinations(t *testing.T, ds dstore.Datastore) {
218229
offsets := []int{
219230
0,
220-
10,
221-
95,
222-
100,
231+
ElemCount / 10,
232+
ElemCount - 5,
233+
ElemCount,
223234
}
224235
limits := []int{
225236
0,
226237
1,
227-
10,
228-
100,
238+
ElemCount / 10,
239+
ElemCount,
229240
}
230241
filters := [][]dsq.Filter{
231242
{dsq.FilterKeyCompare{
@@ -251,7 +262,7 @@ func SubtestCombinations(t *testing.T, ds dstore.Datastore) {
251262
lengths := []int{
252263
0,
253264
1,
254-
100,
265+
ElemCount / 10,
255266
}
256267
perms(
257268
func(perm []int) {
@@ -347,7 +358,7 @@ func SubtestPrefix(t *testing.T, ds dstore.Datastore) {
347358
t.Run(prefix, func(t *testing.T) {
348359
subtestQuery(t, ds, dsq.Query{
349360
Prefix: prefix,
350-
}, 100)
361+
}, ElemCount)
351362
})
352363
}
353364
test("")

0 commit comments

Comments
 (0)