From 1f5fb0208b04dc891c56060f4842003ebed22c16 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Wed, 14 May 2014 18:08:55 -0600 Subject: Add strict mode. --- tx_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tx_test.go') diff --git a/tx_test.go b/tx_test.go index e466765..7bf369b 100644 --- a/tx_test.go +++ b/tx_test.go @@ -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) -- cgit v1.2.3