MCPcopy
hub / github.com/etcd-io/bbolt / TestCursor_EmptyBucket

Function TestCursor_EmptyBucket

cursor_test.go:364–385  ·  view source on GitHub ↗

Ensure that a cursor can iterate over an empty bucket without error.

(t *testing.T)

Source from the content-addressed store, hash-verified

362
363// Ensure that a cursor can iterate over an empty bucket without error.
364func TestCursor_EmptyBucket(t *testing.T) {
365 db := btesting.MustCreateDB(t)
366 if err := db.Update(func(tx *bolt.Tx) error {
367 _, err := tx.CreateBucket([]byte("widgets"))
368 return err
369 }); err != nil {
370 t.Fatal(err)
371 }
372
373 if err := db.View(func(tx *bolt.Tx) error {
374 c := tx.Bucket([]byte("widgets")).Cursor()
375 k, v := c.First()
376 if k != nil {
377 t.Fatalf("unexpected key: %v", k)
378 } else if v != nil {
379 t.Fatalf("unexpected value: %v", v)
380 }
381 return nil
382 }); err != nil {
383 t.Fatal(err)
384 }
385}
386
387// Ensure that a Tx cursor can reverse iterate over an empty bucket without error.
388func TestCursor_EmptyBucketReverse(t *testing.T) {

Callers

nothing calls this directly

Calls 9

MustCreateDBFunction · 0.92
UpdateMethod · 0.80
ViewMethod · 0.80
FirstMethod · 0.80
FatalMethod · 0.65
FatalfMethod · 0.65
CreateBucketMethod · 0.45
CursorMethod · 0.45
BucketMethod · 0.45

Tested by

no test coverage detected