aboutsummaryrefslogtreecommitdiff
path: root/tx_test.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-04-29 07:25:14 -0600
committerBen Johnson <benbjohnson@yahoo.com>2014-04-29 07:25:14 -0600
commite3957cd0de7d86b772ec20e93700c3f6e44d378e (patch)
treee3dfea31f99dbc32a178d781ded12f3bc103a369 /tx_test.go
parentMerge pull request #142 from extemporalgenome/Printf-byteslice (diff)
downloaddedo-e3957cd0de7d86b772ec20e93700c3f6e44d378e.tar.gz
dedo-e3957cd0de7d86b772ec20e93700c3f6e44d378e.tar.xz
Add Tx.Cursor().
This commit adds the Cursor() function to Tx. This allows iteration on the root bucket in a similar way to iteration on other buckets. Fixes #141.
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 e3296ef..61fa5d9 100644
--- a/tx_test.go
+++ b/tx_test.go
@@ -36,6 +36,31 @@ func TestTx_Commit_ReadOnly(t *testing.T) {
})
}
+// Ensure that a transaction can retrieve a cursor on the root bucket.
+func TestTx_Cursor(t *testing.T) {
+ withOpenDB(func(db *DB, path string) {
+ db.Update(func(tx *Tx) error {
+ tx.CreateBucket([]byte("widgets"))
+ tx.CreateBucket([]byte("woojits"))
+ c := tx.Cursor()
+
+ k, v := c.First()
+ assert.Equal(t, "widgets", string(k))
+ assert.Nil(t, v)
+
+ k, v = c.Next()
+ assert.Equal(t, "woojits", string(k))
+ assert.Nil(t, v)
+
+ k, v = c.Next()
+ assert.Nil(t, k)
+ assert.Nil(t, v)
+
+ return nil
+ })
+ })
+}
+
// Ensure that creating a bucket with a read-only transaction returns an error.
func TestTx_CreateBucket_ReadOnly(t *testing.T) {
withOpenDB(func(db *DB, path string) {