| 68 | } |
| 69 | |
| 70 | func testRepeatCursorOperations_NextPrevNext(t *testing.T, b *bolt.Bucket) { |
| 71 | c := b.Cursor() |
| 72 | c.First() |
| 73 | startKey := []byte(fmt.Sprintf("%05d", 2)) |
| 74 | returnedKey, _ := c.Seek(startKey) |
| 75 | require.Equal(t, startKey, returnedKey) |
| 76 | |
| 77 | // Step 1: verify next |
| 78 | for i := 3; i < 1000; i++ { |
| 79 | expectedKey := []byte(fmt.Sprintf("%05d", i)) |
| 80 | actualKey, _ := c.Next() |
| 81 | require.Equal(t, expectedKey, actualKey) |
| 82 | } |
| 83 | |
| 84 | // Once we've reached the end, it should always return nil no matter how many times we call `Next`. |
| 85 | for i := 0; i < 10; i++ { |
| 86 | k, _ := c.Next() |
| 87 | require.Equal(t, []byte(nil), k) |
| 88 | } |
| 89 | |
| 90 | // Step 2: verify prev |
| 91 | for i := 998; i >= 0; i-- { |
| 92 | expectedKey := []byte(fmt.Sprintf("%05d", i)) |
| 93 | actualKey, _ := c.Prev() |
| 94 | require.Equal(t, expectedKey, actualKey) |
| 95 | } |
| 96 | |
| 97 | // Once we've reached the beginning, it should always return nil no matter how many times we call `Prev`. |
| 98 | for i := 0; i < 10; i++ { |
| 99 | k, _ := c.Prev() |
| 100 | require.Equal(t, []byte(nil), k) |
| 101 | } |
| 102 | |
| 103 | // Step 3: verify next again |
| 104 | for i := 1; i < 1000; i++ { |
| 105 | expectedKey := []byte(fmt.Sprintf("%05d", i)) |
| 106 | actualKey, _ := c.Next() |
| 107 | require.Equal(t, expectedKey, actualKey) |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | func testRepeatCursorOperations_PrevNextPrev(t *testing.T, b *bolt.Bucket) { |
| 112 | c := b.Cursor() |