aboutsummaryrefslogtreecommitdiff
path: root/tx_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'tx_test.go')
-rw-r--r--tx_test.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/tx_test.go b/tx_test.go
index afdbb02..fe33869 100644
--- a/tx_test.go
+++ b/tx_test.go
@@ -13,6 +13,33 @@ import (
"github.com/stretchr/testify/assert"
)
+// Ensure that committing a closed transaction returns an error.
+func TestTxCommitClosed(t *testing.T) {
+ withOpenDB(func(db *DB, path string) {
+ tx, _ := db.RWTx()
+ tx.CreateBucket("foo")
+ assert.NoError(t, tx.Commit())
+ assert.Equal(t, tx.Commit(), ErrTxClosed)
+ })
+}
+
+// Ensure that rolling back a closed transaction returns an error.
+func TestTxRollbackClosed(t *testing.T) {
+ withOpenDB(func(db *DB, path string) {
+ tx, _ := db.RWTx()
+ assert.NoError(t, tx.Rollback())
+ assert.Equal(t, tx.Rollback(), ErrTxClosed)
+ })
+}
+
+// Ensure that committing a read-only transaction returns an error.
+func TestTxCommitReadOnly(t *testing.T) {
+ withOpenDB(func(db *DB, path string) {
+ tx, _ := db.Tx()
+ assert.Equal(t, tx.Commit(), ErrTxNotWritable)
+ })
+}
+
// Ensure that the database can retrieve a list of buckets.
func TestTxBuckets(t *testing.T) {
withOpenDB(func(db *DB, path string) {
@@ -41,6 +68,15 @@ func TestTxCreateBucketReadOnly(t *testing.T) {
})
}
+// Ensure that creating a bucket on a closed transaction returns an error.
+func TestTxCreateBucketClosed(t *testing.T) {
+ withOpenDB(func(db *DB, path string) {
+ tx, _ := db.RWTx()
+ tx.Commit()
+ assert.Equal(t, tx.CreateBucket("foo"), ErrTxClosed)
+ })
+}
+
// Ensure that a Tx can retrieve a bucket.
func TestTxBucket(t *testing.T) {
withOpenDB(func(db *DB, path string) {
@@ -204,6 +240,15 @@ func TestTxDeleteBucket(t *testing.T) {
})
}
+// Ensure that deleting a bucket on a closed transaction returns an error.
+func TestTxDeleteBucketClosed(t *testing.T) {
+ withOpenDB(func(db *DB, path string) {
+ tx, _ := db.RWTx()
+ tx.Commit()
+ assert.Equal(t, tx.DeleteBucket("foo"), ErrTxClosed)
+ })
+}
+
// Ensure that deleting a bucket with a read-only transaction returns an error.
func TestTxDeleteBucketReadOnly(t *testing.T) {
withOpenDB(func(db *DB, path string) {