aboutsummaryrefslogtreecommitdiff
path: root/transaction_test.go
blob: 084ef6d3ae7cdb1074215bd06ae2f50dd4fb1c1e (plain) (blame)
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
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.RWTransaction()
		err := txn.CreateBucket("foo")
		if assert.NoError(t, err) {
			assert.NotNil(t, txn.Bucket("foo"))
		}
	})
}

// Ensure that an existing bucket cannot be created.
func TestTransactionCreateExistingBucket(t *testing.T) {
	withOpenDB(func(db *DB, path string) {
		txn, _ := db.RWTransaction()
		txn.CreateBucket("foo")
		err := txn.CreateBucket("foo")
		assert.Equal(t, err, BucketAlreadyExistsError)
	})
}