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

Function TestCursor_Restart

cursor_test.go:545–587  ·  view source on GitHub ↗

Ensure that a Tx cursor can restart from the beginning.

(t *testing.T)

Source from the content-addressed store, hash-verified

543
544// Ensure that a Tx cursor can restart from the beginning.
545func TestCursor_Restart(t *testing.T) {
546 db := btesting.MustCreateDB(t)
547
548 if err := db.Update(func(tx *bolt.Tx) error {
549 b, err := tx.CreateBucket([]byte("widgets"))
550 if err != nil {
551 t.Fatal(err)
552 }
553 if err := b.Put([]byte("bar"), []byte{}); err != nil {
554 t.Fatal(err)
555 }
556 if err := b.Put([]byte("foo"), []byte{}); err != nil {
557 t.Fatal(err)
558 }
559 return nil
560 }); err != nil {
561 t.Fatal(err)
562 }
563
564 tx, err := db.Begin(false)
565 if err != nil {
566 t.Fatal(err)
567 }
568 c := tx.Bucket([]byte("widgets")).Cursor()
569
570 if k, _ := c.First(); !bytes.Equal(k, []byte("bar")) {
571 t.Fatalf("unexpected key: %v", k)
572 }
573 if k, _ := c.Next(); !bytes.Equal(k, []byte("foo")) {
574 t.Fatalf("unexpected key: %v", k)
575 }
576
577 if k, _ := c.First(); !bytes.Equal(k, []byte("bar")) {
578 t.Fatalf("unexpected key: %v", k)
579 }
580 if k, _ := c.Next(); !bytes.Equal(k, []byte("foo")) {
581 t.Fatalf("unexpected key: %v", k)
582 }
583
584 if err := tx.Rollback(); err != nil {
585 t.Fatal(err)
586 }
587}
588
589// Ensure that a cursor can skip over empty pages that have been deleted.
590func TestCursor_First_EmptyPages(t *testing.T) {

Callers

nothing calls this directly

Calls 12

MustCreateDBFunction · 0.92
UpdateMethod · 0.80
BeginMethod · 0.80
FirstMethod · 0.80
NextMethod · 0.80
FatalMethod · 0.65
FatalfMethod · 0.65
RollbackMethod · 0.65
CreateBucketMethod · 0.45
PutMethod · 0.45
CursorMethod · 0.45
BucketMethod · 0.45

Tested by

no test coverage detected