MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / TestIterator_SeekNonExistent

Function TestIterator_SeekNonExistent

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

Source from the content-addressed store, hash-verified

355}
356
357func TestIterator_SeekNonExistent(t *testing.T) {
358 bucket := "bucket"
359
360 runNutsDBTest(t, nil, func(t *testing.T, db *DB) {
361 txCreateBucket(t, db, DataStructureBTree, bucket, nil)
362
363 // Insert keys 0, 2, 4, 6, 8 (even numbers only)
364 for i := 0; i < 10; i += 2 {
365 txPut(t, db, bucket, testutils.GetTestBytes(i), testutils.GetTestBytes(i), Persistent, nil, nil)
366 }
367
368 _ = db.View(func(tx *Tx) error {
369 iterator := NewIterator(tx, bucket, IteratorOptions{Reverse: false})
370 defer iterator.Release()
371
372 // Seek to key 3 (doesn't exist, should position at 4)
373 found := iterator.Seek(testutils.GetTestBytes(3))
374 require.True(t, found)
375 require.True(t, iterator.Valid())
376
377 key := iterator.Key()
378 require.Equal(t, testutils.GetTestBytes(4), key)
379
380 return nil
381 })
382 })
383}
384
385func TestIterator_MultipleSeeks(t *testing.T) {
386 bucket := "bucket"

Callers

nothing calls this directly

Calls 10

ReleaseMethod · 0.95
SeekMethod · 0.95
ValidMethod · 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