MCPcopy Index your code
hub / github.com/nutsdb/nutsdb / TestIterator_Rewind

Function TestIterator_Rewind

iterator_test.go:166–197  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

164}
165
166func TestIterator_Rewind(t *testing.T) {
167 bucket := "bucket"
168
169 runNutsDBTest(t, nil, func(t *testing.T, db *DB) {
170 txCreateBucket(t, db, DataStructureBTree, bucket, nil)
171
172 for i := 0; i < 50; i++ {
173 txPut(t, db, bucket, testutils.GetTestBytes(i), testutils.GetTestBytes(i), Persistent, nil, nil)
174 }
175
176 _ = db.View(func(tx *Tx) error {
177 iterator := NewIterator(tx, bucket, IteratorOptions{Reverse: false})
178 defer iterator.Release()
179
180 // Move to position 10
181 for i := 0; i < 10; i++ {
182 require.True(t, iterator.Valid())
183 iterator.Next()
184 }
185
186 // Rewind back to start
187 require.True(t, iterator.Rewind())
188 require.True(t, iterator.Valid())
189
190 // Verify we're at the first element
191 key := iterator.Key()
192 require.Equal(t, testutils.GetTestBytes(0), key)
193
194 return nil
195 })
196 })
197}
198
199func TestIterator_Rewind_Reverse(t *testing.T) {
200 bucket := "bucket"

Callers

nothing calls this directly

Calls 11

ReleaseMethod · 0.95
ValidMethod · 0.95
NextMethod · 0.95
RewindMethod · 0.95
KeyMethod · 0.95
GetTestBytesFunction · 0.92
runNutsDBTestFunction · 0.85
txCreateBucketFunction · 0.85
txPutFunction · 0.85
NewIteratorFunction · 0.85
ViewMethod · 0.80

Tested by

no test coverage detected