aboutsummaryrefslogtreecommitdiff
path: root/rwtransaction_test.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-02-07 22:55:25 -0700
committerBen Johnson <benbjohnson@yahoo.com>2014-02-08 23:13:54 -0700
commit3da04c52b991337e74c72f2c76bd1aa9df77eab2 (patch)
treed31bed34f7fe34eb8c5a21f311a1103ed4b58b2a /rwtransaction_test.go
parentRefactor node lookup. (diff)
downloaddedo-3da04c52b991337e74c72f2c76bd1aa9df77eab2.tar.gz
dedo-3da04c52b991337e74c72f2c76bd1aa9df77eab2.tar.xz
Rebalance after deletion.
Diffstat (limited to 'rwtransaction_test.go')
-rw-r--r--rwtransaction_test.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/rwtransaction_test.go b/rwtransaction_test.go
index f027e8b..5bf3f9f 100644
--- a/rwtransaction_test.go
+++ b/rwtransaction_test.go
@@ -136,3 +136,44 @@ func TestRWTransactionPutMultiple(t *testing.T) {
}
fmt.Fprint(os.Stderr, "\n")
}
+
+// Ensure that a transaction can delete all key/value pairs and return to a single leaf page.
+func TestRWTransactionDelete(t *testing.T) {
+ f := func(items testdata) bool {
+ withOpenDB(func(db *DB, path string) {
+ // Bulk insert all values.
+ db.CreateBucket("widgets")
+ rwtxn, _ := db.RWTransaction()
+ for _, item := range items {
+ assert.NoError(t, rwtxn.Put("widgets", item.Key, item.Value))
+ }
+ assert.NoError(t, rwtxn.Commit())
+
+ // Remove items one at a time and check consistency.
+ for i, item := range items {
+ assert.NoError(t, db.Delete("widgets", item.Key))
+
+ // Anything before our deletion index should be nil.
+ txn, _ := db.Transaction()
+ for j, exp := range items {
+ if j > i {
+ if !assert.Equal(t, exp.Value, txn.Get("widgets", exp.Key)) {
+ t.FailNow()
+ }
+ } else {
+ if !assert.Nil(t, txn.Get("widgets", exp.Key)) {
+ t.FailNow()
+ }
+ }
+ }
+ txn.Close()
+ }
+ })
+ fmt.Fprint(os.Stderr, ".")
+ return true
+ }
+ if err := quick.Check(f, qconfig()); err != nil {
+ t.Error(err)
+ }
+ fmt.Fprint(os.Stderr, "\n")
+}