(t *testing.T)
| 355 | } |
| 356 | |
| 357 | func 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 | |
| 385 | func TestIterator_MultipleSeeks(t *testing.T) { |
| 386 | bucket := "bucket" |
nothing calls this directly
no test coverage detected