TestCursor_RepeatOperations verifies that a cursor can continue to iterate over all elements in reverse direction when it has already reached to the end or beginning. Refer to https://github.com/etcd-io/bbolt/issues/733
(t *testing.T)
| 23 | // reached to the end or beginning. |
| 24 | // Refer to https://github.com/etcd-io/bbolt/issues/733 |
| 25 | func TestCursor_RepeatOperations(t *testing.T) { |
| 26 | testCases := []struct { |
| 27 | name string |
| 28 | testFunc func(t2 *testing.T, bucket *bolt.Bucket) |
| 29 | }{ |
| 30 | { |
| 31 | name: "Repeat NextPrevNext", |
| 32 | testFunc: testRepeatCursorOperations_NextPrevNext, |
| 33 | }, |
| 34 | { |
| 35 | name: "Repeat PrevNextPrev", |
| 36 | testFunc: testRepeatCursorOperations_PrevNextPrev, |
| 37 | }, |
| 38 | } |
| 39 | |
| 40 | for _, tc := range testCases { |
| 41 | t.Run(tc.name, func(t *testing.T) { |
| 42 | db := btesting.MustCreateDBWithOption(t, &bolt.Options{PageSize: 4096}) |
| 43 | |
| 44 | bucketName := []byte("data") |
| 45 | |
| 46 | _ = db.Update(func(tx *bolt.Tx) error { |
| 47 | b, _ := tx.CreateBucketIfNotExists(bucketName) |
| 48 | testCursorRepeatOperations_PrepareData(t, b) |
| 49 | return nil |
| 50 | }) |
| 51 | |
| 52 | _ = db.View(func(tx *bolt.Tx) error { |
| 53 | b := tx.Bucket(bucketName) |
| 54 | tc.testFunc(t, b) |
| 55 | return nil |
| 56 | }) |
| 57 | }) |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | func testCursorRepeatOperations_PrepareData(t *testing.T, b *bolt.Bucket) { |
| 62 | // ensure we have at least one branch page. |
nothing calls this directly
no test coverage detected