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
|
package bolt
import (
"testing"
"github.com/stretchr/testify/assert"
)
// Ensure that a bucket can be created and retrieved.
func TestTransactionCreateBucket(t *testing.T) {
withOpenDB(func(db *DB, path string) {
txn, _ := db.Transaction(false)
b, err := txn.CreateBucket("foo", false)
if assert.NoError(t, err) && assert.NotNil(t, b) {
b2, err := txn.Bucket("foo")
assert.NoError(t, err)
assert.Equal(t, b, b2)
}
})
}
// Ensure that a user-created transaction cannot be used to create a bucket.
func TestTransactionInvalidCreateBucket(t *testing.T) {
withOpenDB(func(db *DB, path string) {
txn := new(Transaction)
_, err := txn.CreateBucket("foo", false)
assert.Equal(t, err, InvalidTransactionError)
})
}
// Ensure that an existing bucket cannot be created.
func TestTransactionCreateExistingBucket(t *testing.T) {
withOpenDB(func(db *DB, path string) {
txn, _ := db.Transaction(false)
txn.CreateBucket("foo", false)
_, err := txn.CreateBucket("foo", false)
assert.Equal(t, err, BucketAlreadyExistsError)
})
}
|