Ensure that a Tx cursor can restart from the beginning.
(t *testing.T)
| 543 | |
| 544 | // Ensure that a Tx cursor can restart from the beginning. |
| 545 | func 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. |
| 590 | func TestCursor_First_EmptyPages(t *testing.T) { |
nothing calls this directly
no test coverage detected