-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathraw_test.go
140 lines (103 loc) · 2.37 KB
/
raw_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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package goriak
import (
"reflect"
"sort"
"testing"
)
func TestSetRaw(t *testing.T) {
data := []byte{1, 10, 2, 9, 3, 8}
res, err := Bucket("json", "default").SetRaw(data).Run(con())
if err != nil {
t.Error(err)
}
var v []byte
res, err = Bucket("json", "default").GetRaw(res.Key, &v).Run(con())
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(data, v) {
t.Error("Not equal")
}
}
func TestSetRawWithIndex(t *testing.T) {
c := con()
strs := []string{"Hello", "Hej", "Hallo"}
var keys []string
for _, s := range strs {
res, err := Bucket("json", "default").
SetRaw([]byte(s)).
AddToIndex("testA_bin", "hello").
AddToIndex("testB_bin", "world").
Run(c)
if err != nil {
t.Error(err)
}
keys = append(keys, res.Key)
}
var foundKeys []string
cb := func(r SecondaryIndexQueryResult) {
if !r.IsComplete {
foundKeys = append(foundKeys, r.Key)
}
}
Bucket("json", "default").KeysInIndex("testA_bin", "hello", cb).Run(c)
sort.Strings(keys)
sort.Strings(foundKeys)
if !reflect.DeepEqual(keys, foundKeys) {
t.Log("Exected:", keys)
t.Log("Found:", foundKeys)
t.Error("Not equal 1")
}
foundKeys = []string{}
Bucket("json", "default").KeysInIndex("testB_bin", "world", cb).Run(c)
sort.Strings(foundKeys)
if !reflect.DeepEqual(keys, foundKeys) {
t.Log("Exected:", keys)
t.Log("Found:", foundKeys)
t.Error("Not equal 2")
}
}
func TestSetRawAddToMultipleIndexes(t *testing.T) {
c := con()
res, err := Bucket("json", "default").
SetRaw([]byte("fooooobar")).
AddToIndex("testC_bin", "foo").
AddToIndex("testC_bin", "bar").
Run(c)
if err != nil {
t.Error(err)
return
}
foundCount := 0
foundCorrect := false
cb := func(r SecondaryIndexQueryResult) {
if !r.IsComplete {
foundCount++
if r.Key == res.Key {
foundCorrect = true
}
}
}
_, err = Bucket("json", "default").KeysInIndex("testC_bin", "foo", cb).Run(c)
if err != nil {
t.Error(err)
}
if foundCount != 1 {
t.Error("Unexpected count 1. Expected 1, got ", foundCount)
}
if !foundCorrect {
t.Error("Did not find the correct value 1")
}
foundCount = 0
foundCorrect = false
Bucket("json", "default").KeysInIndex("testC_bin", "bar", cb).Run(c)
if err != nil {
t.Error(err)
}
if foundCount != 1 {
t.Error("Unexpected count 2. Expected 1, got ", foundCount)
}
if !foundCorrect {
t.Error("Did not find the correct value 2")
}
}