-
Notifications
You must be signed in to change notification settings - Fork 7
/
bucket_test.go
97 lines (84 loc) · 2.11 KB
/
bucket_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
package riaken_core
import (
"testing"
"github.com/golang/protobuf/proto"
"github.com/riaken/riaken-core/rpb"
)
func TestBucketListKeys(t *testing.T) {
client := dial()
defer client.Close()
session := client.Session()
defer session.Release()
bucket := session.GetBucket("b2")
object := bucket.Object("o2")
if _, err := object.Store([]byte("o2-data")); err != nil {
t.Error(err.Error())
}
var keys [][]byte
// Loop until done is received from Riak
for out, err := bucket.ListKeys(); !out.GetDone(); out, err = bucket.ListKeys() {
if err != nil {
t.Error(err.Error())
break
}
keys = append(keys, out.GetKeys()...)
}
if len(keys) > 0 {
if string(keys[0]) != "o2" {
t.Errorf("expected: o2, got: %s", keys[0])
}
}
if _, err := object.Delete(); err != nil {
t.Error(err.Error())
}
}
func TestBucketSetGetProps(t *testing.T) {
client := dial()
defer client.Close()
session := client.Session()
defer session.Release()
bucket := session.GetBucket("b2")
props := &rpb.RpbBucketProps{
NVal: proto.Uint32(1),
AllowMult: proto.Bool(true),
}
if ok, err := bucket.SetBucketProps(props); !ok {
t.Error("could not set bucket props")
} else if err != nil {
t.Error(err.Error())
}
out, err := bucket.GetBucketProps()
if err != nil {
t.Error(err.Error())
}
if out.GetProps().GetAllowMult() != true {
t.Errorf("expected: true, got: %t", out.GetProps().GetAllowMult())
}
}
func TestBucketSetBucketType(t *testing.T) {
client := dial()
defer client.Close()
session := client.Session()
defer session.Release()
bucket := session.GetBucket("b2").Type("test_maps")
props := &rpb.RpbBucketProps{
AllowMult: proto.Bool(true),
}
if ok, err := bucket.SetBucketType(props); !ok {
t.Error("could not set bucket props")
} else if err != nil {
t.Error(err.Error())
}
}
func TestBucketResetBucket(t *testing.T) {
client := dial()
defer client.Close()
session := client.Session()
defer session.Release()
bucket := session.GetBucket("b2").Type("test_maps")
if ok, err := bucket.ResetBucket(); !ok {
t.Error("could not set bucket props")
} else if err != nil {
t.Error(err.Error())
}
}