diff options
Diffstat (limited to 'transaction_test.go')
-rw-r--r-- | transaction_test.go | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/transaction_test.go b/transaction_test.go index 0b03d5e..6365368 100644 --- a/transaction_test.go +++ b/transaction_test.go @@ -3,20 +3,37 @@ package bolt import ( "testing" -// "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/assert" ) -//-------------------------------------- -// Cursor() -//-------------------------------------- +// 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 a read transaction can get a cursor. -func TestTransactionCursor(t *testing.T) { +// Ensure that an existing bucket cannot be created. +func TestTransactionCreateExistingBucket(t *testing.T) { withOpenDB(func(db *DB, path string) { - /* txn, _ := db.Transaction(false) - c := txn.Cursor() - assert.NotNil(t, c) - */ + txn.CreateBucket("foo", false) + _, err := txn.CreateBucket("foo", false) + assert.Equal(t, err, BucketAlreadyExistsError) }) } |