Skip to content

Commit

Permalink
Test indexed update
Browse files Browse the repository at this point in the history
  • Loading branch information
bnyeggen committed Mar 11, 2014
1 parent 6f0219e commit 9f2b518
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions indexing_test.go
Expand Up @@ -4,6 +4,7 @@ import (
"io/ioutil"
"math/rand"
"os"
"strings"
"testing"
)

Expand Down Expand Up @@ -93,3 +94,40 @@ func TestIndexing(t *testing.T) {
}
}
}

func TestDBUpdateWhere(t *testing.T) {
f, e := ioutil.TempFile("", "ClownshoesDBTest")
if e != nil {
t.Error("Problem creating db", e)
}
f.Close()
db := NewDB(f.Name())
defer os.Remove(f.Name())

doc1 := NewDocument([]byte("alpha"))
doc2 := NewDocument([]byte("beta"))
doc3 := NewDocument([]byte("gamma"))
db.PutDocument(doc1)
db.PutDocument(doc2)
db.PutDocument(doc3)

db.AddIndex("identity", func(b []byte) string { return string(b) })

upcaser := func(input []byte) ([]byte, bool) {
strInput := string(input)
up := strings.ToUpper(strInput)
if up != strInput {
return []byte(up), true
}
return input, false
}

ct := db.ReplaceDocumentsWhere("identity", "alpha", upcaser)
if ct != 1 {
t.Error("Insufficient documents replaced")
}
docs := db.GetDocumentsWhere("identity", "ALPHA")
if len(docs) != 1 {
t.Error("Indexed documents not retrieved after indexed update")
}
}

0 comments on commit 9f2b518

Please sign in to comment.