From 76f6ead6b0c5bbdc6eaaf487a896e63e6ecf7bc6 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Sun, 23 Mar 2014 10:34:53 -0600 Subject: 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. --- db_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'db_test.go') 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) { -- cgit v1.2.3