aboutsummaryrefslogtreecommitdiff
path: root/c/cursor_test.go
diff options
context:
space:
mode:
authorMartin Kobetic <mkobetic@gmail.com>2014-04-23 15:36:41 +0000
committerMartin Kobetic <mkobetic@gmail.com>2014-04-23 15:36:41 +0000
commit181eb96dc707c1bb4e375b55520d1ad037b2a365 (patch)
tree4d1139b2b7a65d8b796b33549dafa6ee5bfea0f1 /c/cursor_test.go
parentanother test case and minor cleanup (diff)
downloaddedo-181eb96dc707c1bb4e375b55520d1ad037b2a365.tar.gz
dedo-181eb96dc707c1bb4e375b55520d1ad037b2a365.tar.xz
add test for empty bucket handling
Diffstat (limited to 'c/cursor_test.go')
-rw-r--r--c/cursor_test.go26
1 files changed, 25 insertions, 1 deletions
diff --git a/c/cursor_test.go b/c/cursor_test.go
index fa1e6bb..5a8f3e0 100644
--- a/c/cursor_test.go
+++ b/c/cursor_test.go
@@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/assert"
)
-// Ensure that the C cursor can
+// Ensure that the C cursor can seek to first element.
func TestCursor_First(t *testing.T) {
withDB(func(db *bolt.DB) {
db.Update(func(tx *bolt.Tx) error {
@@ -28,6 +28,30 @@ func TestCursor_First(t *testing.T) {
})
}
+// Ensure that a C cursor handles empty bucket properly
+func TestCursor_Empty(t *testing.T) {
+ withDB(func(db *bolt.DB) {
+ db.Update(func(tx *bolt.Tx) error {
+ tx.CreateBucket([]byte("widgets"))
+ return nil
+ })
+ db.View(func(tx *bolt.Tx) error {
+ c := NewCursor(tx.Bucket([]byte("widgets")))
+ key, value := c.First()
+ assert.Equal(t, nil, key)
+ assert.Equal(t, nil, value)
+ key, value = c.Next()
+ assert.Equal(t, nil, key)
+ assert.Equal(t, nil, value)
+ key, value, flags := c.Seek([]byte("bar"))
+ assert.Equal(t, nil, key)
+ assert.Equal(t, nil, value)
+ assert.Equal(t, 0, flags)
+ return nil
+ })
+ })
+}
+
// Ensure that a C cursor can seek to the appropriate keys.
func TestCursor_Seek(t *testing.T) {
withDB(func(db *bolt.DB) {