improved test coverage
This commit is contained in:
parent
f1926093de
commit
aeebcdd7fe
|
@ -131,4 +131,28 @@ func TestIndexReader(t *testing.T) {
|
|||
}
|
||||
reader.Close()
|
||||
|
||||
// now test creating a reader for a field that doesn't exist
|
||||
reader, err = idx.TermFieldReader([]byte("water"), "doesnotexist")
|
||||
if err != nil {
|
||||
t.Errorf("Error accessing term field reader: %v", err)
|
||||
}
|
||||
count = reader.Count()
|
||||
if count != 0 {
|
||||
t.Errorf("expected count 0 for reader of non-existant field")
|
||||
}
|
||||
match, err = reader.Next()
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if match != nil {
|
||||
t.Errorf("expected nil, got %v", match)
|
||||
}
|
||||
match, err = reader.Advance("anywhere")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if match != nil {
|
||||
t.Errorf("expected nil, got %v", match)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ package upside_down
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
|
||||
"github.com/couchbaselabs/bleve/analysis"
|
||||
|
@ -144,7 +143,7 @@ func (udc *UpsideDownCouch) batchRows(addRows []UpsideDownCouchRow, updateRows [
|
|||
}
|
||||
tr.freq -= 1 // incr
|
||||
} else {
|
||||
log.Panic(fmt.Sprintf("unexpected missing row, deleting term, expected count row to exit: %v", tr.Key()))
|
||||
return fmt.Errorf("unexpected missing row, deleting term, expected count row to exist: %v", tr.Key())
|
||||
}
|
||||
|
||||
if tr.freq == 0 {
|
||||
|
@ -420,8 +419,7 @@ func (udc *UpsideDownCouch) TermFieldReader(term []byte, fieldName string) (inde
|
|||
if fieldExists {
|
||||
return newUpsideDownCouchTermFieldReader(udc, term, uint16(fieldIndex))
|
||||
}
|
||||
log.Printf("fields: %v", udc.fieldIndexes)
|
||||
return nil, fmt.Errorf("No field named `%s` in the schema", fieldName)
|
||||
return newUpsideDownCouchTermFieldReader(udc, []byte{BYTE_SEPARATOR}, 0)
|
||||
}
|
||||
|
||||
func defaultWriteOptions() *levigo.WriteOptions {
|
||||
|
|
|
@ -114,6 +114,14 @@ func TestIndexInsertThenDelete(t *testing.T) {
|
|||
}
|
||||
expectedCount += 1
|
||||
|
||||
doc2 := document.NewDocument("2")
|
||||
doc2.AddField(document.NewTextField("name", []byte("test")))
|
||||
err = idx.Update(doc2)
|
||||
if err != nil {
|
||||
t.Errorf("Error updating index: %v", err)
|
||||
}
|
||||
expectedCount += 1
|
||||
|
||||
docCount = idx.DocCount()
|
||||
if docCount != expectedCount {
|
||||
t.Errorf("Expected document count to be %d got %d", expectedCount, docCount)
|
||||
|
@ -130,6 +138,17 @@ func TestIndexInsertThenDelete(t *testing.T) {
|
|||
t.Errorf("Expected document count to be %d got %d", expectedCount, docCount)
|
||||
}
|
||||
|
||||
err = idx.Delete("2")
|
||||
if err != nil {
|
||||
t.Errorf("Error deleting entry from index: %v", err)
|
||||
}
|
||||
expectedCount -= 1
|
||||
|
||||
docCount = idx.DocCount()
|
||||
if docCount != expectedCount {
|
||||
t.Errorf("Expected document count to be %d got %d", expectedCount, docCount)
|
||||
}
|
||||
|
||||
// should have 2 row (1 for version, 1 for schema field)
|
||||
expectedLength := uint64(1 + 1)
|
||||
rowCount := idx.rowCount()
|
||||
|
@ -196,7 +215,8 @@ func TestIndexInsertMultiple(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("error opening index: %v", err)
|
||||
}
|
||||
defer idx.Close()
|
||||
|
||||
var expectedCount uint64 = 0
|
||||
|
||||
doc := document.NewDocument("1")
|
||||
doc.AddField(document.NewTextField("name", []byte("test")))
|
||||
|
@ -204,6 +224,7 @@ func TestIndexInsertMultiple(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("Error updating index: %v", err)
|
||||
}
|
||||
expectedCount++
|
||||
|
||||
doc = document.NewDocument("2")
|
||||
doc.AddField(document.NewTextField("name", []byte("test")))
|
||||
|
@ -211,6 +232,7 @@ func TestIndexInsertMultiple(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("Error updating index: %v", err)
|
||||
}
|
||||
expectedCount++
|
||||
|
||||
// should have 4 rows (1 for version, 1 for schema field, and 2 for single term, and 1 for the term count, and 2 for the back index entries)
|
||||
expectedLength := uint64(1 + 1 + 2 + 1 + 2)
|
||||
|
@ -218,4 +240,26 @@ func TestIndexInsertMultiple(t *testing.T) {
|
|||
if rowCount != expectedLength {
|
||||
t.Errorf("expected %d rows, got: %d", expectedLength, rowCount)
|
||||
}
|
||||
|
||||
// close and reopen and and one more to testing counting works correctly
|
||||
idx.Close()
|
||||
idx = NewUpsideDownCouch("test")
|
||||
|
||||
err = idx.Open()
|
||||
if err != nil {
|
||||
t.Errorf("error opening index: %v", err)
|
||||
}
|
||||
|
||||
doc = document.NewDocument("3")
|
||||
doc.AddField(document.NewTextField("name", []byte("test")))
|
||||
err = idx.Update(doc)
|
||||
if err != nil {
|
||||
t.Errorf("Error updating index: %v", err)
|
||||
}
|
||||
expectedCount++
|
||||
|
||||
docCount := idx.DocCount()
|
||||
if docCount != expectedCount {
|
||||
t.Errorf("expected doc count: %d, got %d", expectedCount, docCount)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue