Skip to content

Commit

Permalink
add TestSeekToFirstKey
Browse files Browse the repository at this point in the history
  • Loading branch information
Preetam committed Sep 17, 2016
1 parent 4a47593 commit e155ae3
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lm2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,39 @@ func TestReadLastEntry(t *testing.T) {
}
t.Logf("%+v", c.Stats())
}

func TestSeekToFirstKey(t *testing.T) {
c, err := NewCollection("/tmp/test_seektofirstkey.lm2", 100)
if err != nil {
t.Fatal(err)
}
defer c.Close()

wb := NewWriteBatch()
wb.Set("a", "1")
wb.Set("b", "1")
wb.Set("c", "1")
wb.Set("d", "1")
_, err = c.Update(wb)
if err != nil {
t.Fatal(err)
}

cur, err := c.NewCursor()
if err != nil {
t.Fatal(err)
}

cur.Seek("a")
if !cur.Valid() {
t.Fatal("expected cursor to be valid")
}

if !cur.Next() {
t.Fatal("expected Next() to return true")
}

if cur.Key() != "a" {
t.Fatalf("expected cursor key to be 'a', got %v", cur.Key())
}
}

0 comments on commit e155ae3

Please sign in to comment.