diff options
Diffstat (limited to 'c/cursor_test.go')
-rw-r--r-- | c/cursor_test.go | 26 |
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) { |