-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathddoc_test.go
118 lines (107 loc) · 2.43 KB
/
ddoc_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
package main
import (
"bytes"
"io/ioutil"
"os"
"testing"
)
func TestGetSetDDoc(t *testing.T) {
d, err := ioutil.TempDir("./tmp", "test")
if err != nil {
t.Fatalf("Expected TempDir to work, got: %v", err)
}
defer os.RemoveAll(d)
bs, err := NewBuckets(d,
&BucketSettings{
NumPartitions: MAX_VBUCKETS,
})
defer bs.CloseAll()
b, _ := bs.New("thebucket", bs.settings)
if b.GetDDocVBucket() == nil {
t.Errorf("expected to have a ddoc vbucket")
}
v, err := b.GetDDoc("hi")
if err != nil {
t.Errorf("expecting no ddoc get error for missing ddoc")
}
if v != nil {
t.Errorf("expecting no ddoc for missing ddoc")
}
err = b.SetDDoc("hi", []byte("hello"))
if err != nil {
t.Errorf("not expecting an error")
}
if v != nil {
t.Errorf("not expecting an error")
}
v, err = b.GetDDoc("hi")
if err != nil {
t.Errorf("not expecting an error")
}
if !bytes.Equal(v, []byte("hello")) {
t.Errorf("expecting ddocs to be the same")
}
if err = b.Flush(); err != nil {
t.Errorf("expected flush to work")
}
b2, err := NewBuckets(d,
&BucketSettings{
NumPartitions: MAX_VBUCKETS,
})
defer b2.CloseAll()
if err != nil {
t.Fatalf("Expected NewBuckets() to work on temp dir")
}
b = b2.Get("thebucket")
if b == nil {
t.Errorf("expected the bucket")
}
if b.GetDDocVBucket() == nil {
t.Errorf("expected to have a ddoc vbucket")
}
v, err = b.GetDDoc("hi")
if err != nil {
t.Errorf("not expecting an error")
}
if !bytes.Equal(v, []byte("hello")) {
t.Errorf("expecting ddocs to be the same")
}
v, err = b.GetDDoc("not-a-ddoc")
if err != nil {
t.Errorf("expecting no ddoc get error for missing ddoc")
}
if v != nil {
t.Errorf("expecting no ddoc for missing ddoc")
}
}
func TestGetSetDDocs(t *testing.T) {
d, err := ioutil.TempDir("./tmp", "test")
if err != nil {
t.Fatalf("Expected TempDir to work, got: %v", err)
}
defer os.RemoveAll(d)
bs, err := NewBuckets(d,
&BucketSettings{
NumPartitions: MAX_VBUCKETS,
})
defer bs.CloseAll()
b, _ := bs.New("thebucket", bs.settings)
ddocs := b.GetDDocs()
if ddocs == nil {
t.Errorf("expected non-nil ddocs, got nil")
}
e := DDocs{}
e["hi"] = &DDoc{}
if b.SetDDocs(&e, &e) {
t.Errorf("expected set ddocs to fail on bad CAS")
}
if b.GetDDocs() != ddocs {
t.Errorf("expected get ddocs to still be the same")
}
if !b.SetDDocs(ddocs, &e) {
t.Errorf("expected set ddocs to work")
}
if b.GetDDocs() != &e {
t.Errorf("expected get ddocs to be e")
}
}