diff options
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) |