aboutsummaryrefslogtreecommitdiff
path: root/transaction_test.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-01-17 15:23:39 -0700
committerBen Johnson <benbjohnson@yahoo.com>2014-01-17 15:23:39 -0700
commit153372abd4adbcdb0a8be7eecddcfe5b5c885d9f (patch)
treec4bb425337b467a9f6d06206f03c0101403c8a43 /transaction_test.go
parentAdd system buckets. (diff)
downloaddedo-153372abd4adbcdb0a8be7eecddcfe5b5c885d9f.tar.gz
dedo-153372abd4adbcdb0a8be7eecddcfe5b5c885d9f.tar.xz
Refactoring to RWCursor, RWTxn, and branch/leaf nodes and pages.
Diffstat (limited to 'transaction_test.go')
-rw-r--r--transaction_test.go37
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)
})
}