forked from vincent-petithory/rbolt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bucket_test.go
131 lines (122 loc) · 2.49 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
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
package rbolt_test
import (
"testing"
"github.com/boltdb/bolt"
"github.com/vincent-petithory/rbolt"
)
func TestBucketBucket(t *testing.T) {
runSyncTest(t,
func(tx *bolt.Tx) error {
b, err := tx.CreateBucket([]byte("bucket"))
if err != nil {
return err
}
_, err = b.CreateBucket([]byte("subbucket"))
return err
},
`
bucket/
bucket/subbucket/
bucket/subbucket/k => v
`,
func(tx *rbolt.Tx) error {
// Use the bucket to create a key
return tx.Bucket([]byte("bucket")).Bucket([]byte("subbucket")).Put([]byte("k"), []byte("v"))
},
)
}
func TestBucketCreateBucket(t *testing.T) {
runSyncTest(t,
func(tx *bolt.Tx) error {
_, err := tx.CreateBucket([]byte("bucket"))
return err
},
`bucket/
bucket/subbucket/
`,
func(tx *rbolt.Tx) error {
_, err := tx.Bucket([]byte("bucket")).CreateBucket([]byte("subbucket"))
return err
},
)
}
func TestBucketCreateBucketIfNotExists(t *testing.T) {
runSyncTest(t,
func(tx *bolt.Tx) error {
_, err := tx.CreateBucket([]byte("bucket"))
return err
},
`
bucket/
bucket/subbucket/
`,
func(tx *rbolt.Tx) error {
_, err := tx.Bucket([]byte("bucket")).CreateBucketIfNotExists([]byte("subbucket"))
return err
},
)
}
func TestBucketDelete(t *testing.T) {
runSyncTest(t,
func(tx *bolt.Tx) error {
b, err := tx.CreateBucket([]byte("bucket"))
if err != nil {
return err
}
return b.Put([]byte("k"), []byte("v"))
},
`bucket/`,
func(tx *rbolt.Tx) error {
return tx.Bucket([]byte("bucket")).Delete([]byte("k"))
},
)
}
func TestBucketDeleteBucket(t *testing.T) {
runSyncTest(t,
func(tx *bolt.Tx) error {
b, err := tx.CreateBucket([]byte("bucket"))
if err != nil {
return err
}
_, err = b.CreateBucket([]byte("subbucket"))
return err
},
`bucket/`,
func(tx *rbolt.Tx) error {
return tx.Bucket([]byte("bucket")).DeleteBucket([]byte("subbucket"))
},
)
}
func TestBucketPut(t *testing.T) {
runSyncTest(t,
func(tx *bolt.Tx) error {
_, err := tx.CreateBucket([]byte("bucket"))
return err
},
`
bucket/
bucket/k => v
`,
func(tx *rbolt.Tx) error {
return tx.Bucket([]byte("bucket")).Put([]byte("k"), []byte("v"))
},
)
}
func TestBucketTx(t *testing.T) {
runSyncTest(t,
func(tx *bolt.Tx) error {
_, err := tx.CreateBucket([]byte("bucket"))
return err
},
`
bucket/
bucket2/
`,
func(tx *rbolt.Tx) error {
b := tx.Bucket([]byte("bucket"))
// Use the tx to create a bucket
_, err := b.Tx().CreateBucket([]byte("bucket2"))
return err
},
)
}