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

Function testRepeatCursorOperations_PrevNextPrev

cursor_test.go:111–150  ·  view source on GitHub ↗
(t *testing.T, b *bolt.Bucket)

Source from the content-addressed store, hash-verified

109}
110
111func testRepeatCursorOperations_PrevNextPrev(t *testing.T, b *bolt.Bucket) {
112 c := b.Cursor()
113
114 startKey := []byte(fmt.Sprintf("%05d", 998))
115 returnedKey, _ := c.Seek(startKey)
116 require.Equal(t, startKey, returnedKey)
117
118 // Step 1: verify prev
119 for i := 997; i >= 0; i-- {
120 expectedKey := []byte(fmt.Sprintf("%05d", i))
121 actualKey, _ := c.Prev()
122 require.Equal(t, expectedKey, actualKey)
123 }
124
125 // Once we've reached the beginning, it should always return nil no matter how many times we call `Prev`.
126 for i := 0; i < 10; i++ {
127 k, _ := c.Prev()
128 require.Equal(t, []byte(nil), k)
129 }
130
131 // Step 2: verify next
132 for i := 1; i < 1000; i++ {
133 expectedKey := []byte(fmt.Sprintf("%05d", i))
134 actualKey, _ := c.Next()
135 require.Equal(t, expectedKey, actualKey)
136 }
137
138 // Once we've reached the end, it should always return nil no matter how many times we call `Next`.
139 for i := 0; i < 10; i++ {
140 k, _ := c.Next()
141 require.Equal(t, []byte(nil), k)
142 }
143
144 // Step 3: verify prev again
145 for i := 998; i >= 0; i-- {
146 expectedKey := []byte(fmt.Sprintf("%05d", i))
147 actualKey, _ := c.Prev()
148 require.Equal(t, expectedKey, actualKey)
149 }
150}
151
152// Ensure that a cursor can return a reference to the bucket that created it.
153func TestCursor_Bucket(t *testing.T) {

Callers

nothing calls this directly

Calls 4

SeekMethod · 0.80
PrevMethod · 0.80
NextMethod · 0.80
CursorMethod · 0.45

Tested by

no test coverage detected