MCPcopy Create free account
hub / github.com/couchbase/moss / testIteratorSeekTo

Function testIteratorSeekTo

iterator_test.go:331–451  ·  view source on GitHub ↗
(t *testing.T, startEarly, oneBatch bool,
	startKey, endKey []byte)

Source from the content-addressed store, hash-verified

329}
330
331func testIteratorSeekTo(t *testing.T, startEarly, oneBatch bool,
332 startKey, endKey []byte) {
333 m, _ := NewCollection(CollectionOptions{})
334
335 if startEarly {
336 m.Start()
337 }
338
339 if oneBatch {
340 // Insert 1, 3, 5, 7, 9
341 batch, _ := m.NewBatch(0, 0)
342 for i := 1; i <= 9; i += 2 {
343 x := []byte(fmt.Sprintf("%d", i))
344 batch.Set(x, x)
345 }
346 m.ExecuteBatch(batch, WriteOptions{})
347 batch.Close()
348 } else {
349 // Insert 1, 3, 5
350 batch, _ := m.NewBatch(0, 0)
351 for i := 1; i <= 5; i += 2 {
352 x := []byte(fmt.Sprintf("%d", i))
353 batch.Set(x, x)
354 }
355 m.ExecuteBatch(batch, WriteOptions{})
356 batch.Close()
357
358 // Insert 7, 9
359 batch, _ = m.NewBatch(0, 0)
360 for i := 7; i <= 9; i += 2 {
361 x := []byte(fmt.Sprintf("%d", i))
362 batch.Set(x, x)
363 }
364 m.ExecuteBatch(batch, WriteOptions{})
365 batch.Close()
366 }
367
368 ss, err := m.Snapshot()
369 if err != nil {
370 t.Errorf("expected no snapshot err, got: %v", err)
371 }
372
373 itr, err := ss.StartIterator(nil, nil, IteratorOptions{})
374 if err != nil {
375 t.Errorf("expected no itr err, got: %v", err)
376 }
377
378 err = itr.SeekTo([]byte("0"))
379 if err == ErrIteratorDone {
380 t.Errorf("expected done, got: %v", err)
381 }
382
383 gotk, _, err := itr.Current()
384 if err != nil {
385 t.Errorf("expected no Current err, got: %v", err)
386 }
387
388 expectedk := "1"

Callers 1

TestIteratorSeekToFunction · 0.85

Calls 11

StartMethod · 0.95
NewBatchMethod · 0.95
SetMethod · 0.95
ExecuteBatchMethod · 0.95
CloseMethod · 0.95
SnapshotMethod · 0.95
CloseMethod · 0.95
NewCollectionFunction · 0.85
StartIteratorMethod · 0.65
SeekToMethod · 0.65
CurrentMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…