-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathkeys_in_index_test.go
95 lines (75 loc) · 1.57 KB
/
keys_in_index_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package goriak
import (
"testing"
)
func TestKeysInIndex(t *testing.T) {
type tt struct {
Val string
}
for _, key := range []string{"A", "B", "C", "D", "E", "F", "G"} {
_, err := Bucket("json", "default").SetJSON(tt{Val: key}).AddToIndex("indextest_bin", "AAAA").Key(key).Run(con())
if err != nil {
t.Error(err)
}
}
fetches := 0
keyCount := 0
cb := func(r SecondaryIndexQueryResult) {
if !r.IsComplete {
keyCount++
}
}
var cont []byte
for {
res, err := Bucket("json", "default").
KeysInIndex("indextest_bin", "AAAA", cb).
Limit(3).
IndexContinuation(cont).
Run(con())
if err != nil {
t.Error(err)
}
fetches++
if len(res.Continuation) == 0 {
break
}
cont = res.Continuation
}
if fetches != 3 {
t.Error("Did not do 3 fetches")
}
if keyCount != 7 {
t.Error("did not find 7 keys")
}
}
func TestKeysInIndexRange(t *testing.T) {
type tt struct {
Val string
}
for _, indexVal := range []string{"a", "b", "c", "d", "e"} {
for _, key := range []string{"A", "B", "C", "D", "E", "F", "G"} {
_, err := Bucket("json", "default").SetJSON(tt{Val: key}).AddToIndex("rangetest_bin", indexVal).Key(indexVal + key).Run(con())
if err != nil {
t.Error(err)
}
}
}
keyCount := 0
cb := func(r SecondaryIndexQueryResult) {
//t.Logf("%+v", r)
if !r.IsComplete {
keyCount++
}
}
res, err := Bucket("json", "default").
KeysInIndexRange("rangetest_bin", "b", "d", cb).
Limit(1000).
Run(con())
if err != nil {
t.Error(err)
}
if keyCount != 21 {
t.Error("unexpected count")
}
t.Logf("%+v", res)
}