aboutsummaryrefslogtreecommitdiff
path: root/tx_test.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-05-14 18:08:55 -0600
committerBen Johnson <benbjohnson@yahoo.com>2014-05-14 18:08:55 -0600
commit1f5fb0208b04dc891c56060f4842003ebed22c16 (patch)
treeae88be4c16ec151ffedef201533cb51c9dd61e35 /tx_test.go
parentMerge pull request #162 from Shopify/nested_stats2 (diff)
downloaddedo-1f5fb0208b04dc891c56060f4842003ebed22c16.tar.gz
dedo-1f5fb0208b04dc891c56060f4842003ebed22c16.tar.xz
Add strict mode.
Diffstat (limited to 'tx_test.go')
-rw-r--r--tx_test.go25
1 files changed, 25 insertions, 0 deletions
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)