diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-22 22:54:54 -0700 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-22 22:54:54 -0700 |
commit | 3b2fd8f2d3e376fa7a3f3b2ba665fcd4a5b5bb15 (patch) | |
tree | a2b7de98448c4ddd427449dfe85695fa5c7c9c22 /db_test.go | |
parent | Merge pull request #50 from benbjohnson/api (diff) | |
download | dedo-3b2fd8f2d3e376fa7a3f3b2ba665fcd4a5b5bb15.tar.gz dedo-3b2fd8f2d3e376fa7a3f3b2ba665fcd4a5b5bb15.tar.xz |
Revert "Refactor Transaction/Bucket API."
This reverts commit 1ad2b99f281d587b767b36f886401e81d17915a9.
Diffstat (limited to 'db_test.go')
-rw-r--r-- | db_test.go | 41 |
1 files changed, 10 insertions, 31 deletions
@@ -188,34 +188,14 @@ func TestDBDeleteFromMissingBucket(t *testing.T) { }) } -// Ensure that a Transaction can be retrieved. -func TestDBRWTransaction(t *testing.T) { - withOpenDB(func(db *DB, path string) { - txn, err := db.RWTransaction() - assert.NotNil(t, txn) - assert.NoError(t, err) - assert.Equal(t, txn.DB(), db) - }) -} - -// Ensure that opening a Transaction while the DB is closed returns an error. -func TestRWTransactionOpenWithClosedDB(t *testing.T) { - withDB(func(db *DB, path string) { - txn, err := db.RWTransaction() - assert.Equal(t, err, ErrDatabaseNotOpen) - assert.Nil(t, txn) - }) -} - // Ensure a database can provide a transactional block. func TestDBTransactionBlock(t *testing.T) { withOpenDB(func(db *DB, path string) { - err := db.Do(func(txn *Transaction) error { + err := db.Do(func(txn *RWTransaction) error { txn.CreateBucket("widgets") - b := txn.Bucket("widgets") - b.Put([]byte("foo"), []byte("bar")) - b.Put([]byte("baz"), []byte("bat")) - b.Delete([]byte("foo")) + txn.Put("widgets", []byte("foo"), []byte("bar")) + txn.Put("widgets", []byte("baz"), []byte("bat")) + txn.Delete("widgets", []byte("foo")) return nil }) assert.NoError(t, err) @@ -229,7 +209,7 @@ func TestDBTransactionBlock(t *testing.T) { // Ensure a closed database returns an error while running a transaction block func TestDBTransactionBlockWhileClosed(t *testing.T) { withDB(func(db *DB, path string) { - err := db.Do(func(txn *Transaction) error { + err := db.Do(func(txn *RWTransaction) error { txn.CreateBucket("widgets") return nil }) @@ -353,11 +333,10 @@ func TestDBCopyFile(t *testing.T) { // Ensure the database can return stats about itself. func TestDBStat(t *testing.T) { withOpenDB(func(db *DB, path string) { - db.Do(func(txn *Transaction) error { + db.Do(func(txn *RWTransaction) error { txn.CreateBucket("widgets") - b := txn.Bucket("widgets") for i := 0; i < 10000; i++ { - b.Put([]byte(strconv.Itoa(i)), []byte(strconv.Itoa(i))) + txn.Put("widgets", []byte(strconv.Itoa(i)), []byte(strconv.Itoa(i))) } return nil }) @@ -370,7 +349,7 @@ func TestDBStat(t *testing.T) { t0, _ := db.Transaction() t1, _ := db.Transaction() t2, _ := db.Transaction() - t2.Rollback() + t2.Close() // Obtain stats. stat, err := db.Stat() @@ -382,8 +361,8 @@ func TestDBStat(t *testing.T) { assert.Equal(t, stat.TransactionCount, 2) // Close readers. - t0.Rollback() - t1.Rollback() + t0.Close() + t1.Close() }) } |