-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
map_operation_test.go
84 lines (63 loc) · 1.78 KB
/
map_operation_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
package goriak
import (
"testing"
)
func TestMapOperation(t *testing.T) {
result, errset := bucket().Set(&testmapobject{
A: "Hello",
Set: []string{"One", "Two"},
}).Run(con())
if errset != nil {
t.Error("Set:", errset)
}
var res testmapobject
bucket().Get(result.Key, &res).Run(con())
if len(res.Set) != 2 {
t.Error("Unexpected length. Should be 2, got ", len(res.Set))
}
op := NewMapOperation()
op.AddToSet("Set", []byte("Three"))
_, mapoperr := Bucket("testsuitemap", "maps").MapOperation(op).Context(res.RiakContext).Key(result.Key).Run(con())
if mapoperr != nil {
t.Error("MapOperr:", mapoperr)
}
var res2 testmapobject
_, errget := bucket().Get(result.Key, &res2).Run(con())
if errget != nil {
t.Error("ErrGet:", errget)
}
if len(res2.Set) != 3 {
t.Error("Unexpected length. Should be 3, got ", len(res2.Set))
t.Errorf("%+v", res2)
}
}
func TestMapOperationAlternateOrder(t *testing.T) {
result, errset := bucket().Set(&testmapobject{
A: "Hello",
Set: []string{"One", "Two"},
}).Run(con())
if errset != nil {
t.Error("Set:", errset)
}
var res testmapobject
bucket().Get(result.Key, &res).Run(con())
if len(res.Set) != 2 {
t.Error("Unexpected length. Should be 2, got ", len(res.Set))
}
op := NewMapOperation()
op.AddToSet("Set", []byte("Three"))
// This is where the change is compared to TestMapOperation()
_, mapoperr := Bucket("testsuitemap", "maps").MapOperation(op).Context(res.RiakContext).Key(result.Key).Run(con())
if mapoperr != nil {
t.Error("MapOperr:", mapoperr)
}
var res2 testmapobject
_, errget := bucket().Get(result.Key, &res2).Run(con())
if errget != nil {
t.Error("ErrGet:", errget)
}
if len(res2.Set) != 3 {
t.Error("Unexpected length. Should be 3, got ", len(res2.Set))
t.Errorf("%+v", res2)
}
}