aboutsummaryrefslogtreecommitdiff
path: root/db_test.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-03-23 10:34:53 -0600
committerBen Johnson <benbjohnson@yahoo.com>2014-03-23 10:34:53 -0600
commit76f6ead6b0c5bbdc6eaaf487a896e63e6ecf7bc6 (patch)
tree96a0dbb8820c3eec1a596363875d75f80acd68ca /db_test.go
parentMerge pull request #76 from benbjohnson/fsync (diff)
downloaddedo-76f6ead6b0c5bbdc6eaaf487a896e63e6ecf7bc6.tar.gz
dedo-76f6ead6b0c5bbdc6eaaf487a896e63e6ecf7bc6.tar.xz
Mark Do()/With() transaction as managed.
Transaction created from Do() and With() are now considered "managed". Managed transactions cannot be manually committed or rolled back since the Do() and With() functions provide that functionally automatically. Previously, a Tx could be manually committed and then any changes after that would be lost.
Diffstat (limited to 'db_test.go')
-rw-r--r--db_test.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/db_test.go b/db_test.go
index 04abd75..2882ba8 100644
--- a/db_test.go
+++ b/db_test.go
@@ -111,6 +111,23 @@ func TestDBTxBlockWhileClosed(t *testing.T) {
})
}
+// Ensure a panic occurs while trying to commit a managed transaction.
+func TestDBTxBlockWithManualCommitAndRollback(t *testing.T) {
+ withOpenDB(func(db *DB, path string) {
+ db.Do(func(tx *Tx) error {
+ tx.CreateBucket("widgets")
+ assert.Panics(t, func() { tx.Commit() })
+ assert.Panics(t, func() { tx.Rollback() })
+ return nil
+ })
+ db.With(func(tx *Tx) error {
+ assert.Panics(t, func() { tx.Commit() })
+ assert.Panics(t, func() { tx.Rollback() })
+ return nil
+ })
+ })
+}
+
// Ensure that the database can be copied to a file path.
func TestDBCopyFile(t *testing.T) {
withOpenDB(func(db *DB, path string) {