aboutsummaryrefslogtreecommitdiff
path: root/rwtransaction_test.go
blob: 2bcf25266abe602ae8ea34ffd60de7626f89409e (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package bolt

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

// Ensure that a RWTransaction can be retrieved.
func TestRWTransaction(t *testing.T) {
	withOpenDB(func(db *DB, path string) {
		txn, err := db.RWTransaction()
		assert.NotNil(t, txn)
		assert.NoError(t, err)
	})
}

// Ensure that a bucket can be created and retrieved.
func TestTransactionCreateBucket(t *testing.T) {
	withOpenDB(func(db *DB, path string) {
		// Create a bucket.
		txn, _ := db.RWTransaction()
		err := txn.CreateBucket("widgets")
		assert.NoError(t, err)

		// Commit the transaction.
		err = txn.Commit()
		assert.NoError(t, err)

		// Open a separate read-only transaction.
		rtxn, err := db.Transaction()
		assert.NotNil(t, txn)
		assert.NoError(t, err)

		b := rtxn.Bucket("widgets")
		assert.NoError(t, err)
		if assert.NotNil(t, b) {
			assert.Equal(t, b.Name(), "widgets")
		}
	})
}

// Ensure that an existing bucket cannot be created.
func TestTransactionCreateExistingBucket(t *testing.T) {
	t.Skip("pending")
}