diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-05-14 18:08:55 -0600 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-05-14 18:08:55 -0600 |
commit | 1f5fb0208b04dc891c56060f4842003ebed22c16 (patch) | |
tree | ae88be4c16ec151ffedef201533cb51c9dd61e35 /tx_test.go | |
parent | Merge pull request #162 from Shopify/nested_stats2 (diff) | |
download | dedo-1f5fb0208b04dc891c56060f4842003ebed22c16.tar.gz dedo-1f5fb0208b04dc891c56060f4842003ebed22c16.tar.xz |
Add strict mode.
Diffstat (limited to 'tx_test.go')
-rw-r--r-- | tx_test.go | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -288,6 +288,31 @@ func TestTx_OnCommit_Rollback(t *testing.T) { assert.Equal(t, 0, x) } +// Ensure that a Tx in strict mode will fail when corrupted. +func TestTx_Check_Corrupt(t *testing.T) { + var msg string + func() { + defer func() { + msg = fmt.Sprintf("%s", recover()) + }() + + withOpenDB(func(db *DB, path string) { + db.StrictMode = true + db.Update(func(tx *Tx) error { + tx.CreateBucket([]byte("foo")) + + // Corrupt the DB by adding a page to the freelist. + warn("---") + db.freelist.free(0, tx.page(3)) + + return nil + }) + }) + }() + + assert.Equal(t, "check fail: 1 errors occurred: page 3: already freed", msg) +} + func ExampleTx_Rollback() { // Open the database. db, _ := Open(tempfile(), 0666) |