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

Function TestCursor_QuickCheck_Reverse

cursor_test.go:740–794  ·  view source on GitHub ↗

Ensure that a transaction can iterate over all elements in a bucket in reverse.

(t *testing.T)

Source from the content-addressed store, hash-verified

738
739// Ensure that a transaction can iterate over all elements in a bucket in reverse.
740func TestCursor_QuickCheck_Reverse(t *testing.T) {
741 f := func(items testdata) bool {
742 db := btesting.MustCreateDB(t)
743 defer db.MustClose()
744
745 // Bulk insert all values.
746 tx, err := db.Begin(true)
747 if err != nil {
748 t.Fatal(err)
749 }
750 b, err := tx.CreateBucket([]byte("widgets"))
751 if err != nil {
752 t.Fatal(err)
753 }
754 for _, item := range items {
755 if err := b.Put(item.Key, item.Value); err != nil {
756 t.Fatal(err)
757 }
758 }
759 if err := tx.Commit(); err != nil {
760 t.Fatal(err)
761 }
762
763 // Sort test data.
764 sort.Sort(revtestdata(items))
765
766 // Iterate over all items and check consistency.
767 var index = 0
768 tx, err = db.Begin(false)
769 if err != nil {
770 t.Fatal(err)
771 }
772 c := tx.Bucket([]byte("widgets")).Cursor()
773 for k, v := c.Last(); k != nil && index < len(items); k, v = c.Prev() {
774 if !bytes.Equal(k, items[index].Key) {
775 t.Fatalf("unexpected key: %v", k)
776 } else if !bytes.Equal(v, items[index].Value) {
777 t.Fatalf("unexpected value: %v", v)
778 }
779 index++
780 }
781 if len(items) != index {
782 t.Fatalf("unexpected item count: %v, expected %v", len(items), index)
783 }
784
785 if err := tx.Rollback(); err != nil {
786 t.Fatal(err)
787 }
788
789 return true
790 }
791 if err := quick.Check(f, qconfig()); err != nil {
792 t.Error(err)
793 }
794}
795
796// Ensure that a Tx cursor can iterate over subbuckets.
797func TestCursor_QuickCheck_BucketsOnly(t *testing.T) {

Callers

nothing calls this directly

Calls 15

MustCreateDBFunction · 0.92
revtestdataTypeAlias · 0.85
qconfigFunction · 0.85
MustCloseMethod · 0.80
BeginMethod · 0.80
CommitMethod · 0.80
LastMethod · 0.80
PrevMethod · 0.80
CheckMethod · 0.80
FatalMethod · 0.65
FatalfMethod · 0.65
RollbackMethod · 0.65

Tested by

no test coverage detected