2014-07-30 18:30:38 +02:00
|
|
|
// Copyright (c) 2014 Couchbase, Inc.
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
// except in compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the
|
|
|
|
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
|
|
// either express or implied. See the License for the specific language governing permissions
|
|
|
|
// and limitations under the License.
|
2014-05-15 16:18:43 +02:00
|
|
|
package store_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2014-08-28 21:38:57 +02:00
|
|
|
"github.com/blevesearch/bleve/index/store"
|
2014-05-15 16:18:43 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func CommonTestKVStore(t *testing.T, s store.KVStore) {
|
|
|
|
|
|
|
|
err := s.Set([]byte("a"), []byte("val-a"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
err = s.Set([]byte("z"), []byte("val-z"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
err = s.Delete([]byte("z"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
batch := s.NewBatch()
|
|
|
|
batch.Set([]byte("b"), []byte("val-b"))
|
|
|
|
batch.Set([]byte("c"), []byte("val-c"))
|
|
|
|
batch.Set([]byte("d"), []byte("val-d"))
|
|
|
|
batch.Set([]byte("e"), []byte("val-e"))
|
|
|
|
batch.Set([]byte("f"), []byte("val-f"))
|
|
|
|
batch.Set([]byte("g"), []byte("val-g"))
|
|
|
|
batch.Set([]byte("h"), []byte("val-h"))
|
|
|
|
batch.Set([]byte("i"), []byte("val-i"))
|
|
|
|
batch.Set([]byte("j"), []byte("val-j"))
|
|
|
|
|
|
|
|
err = batch.Execute()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
it := s.Iterator([]byte("b"))
|
|
|
|
key, val, valid := it.Current()
|
|
|
|
if !valid {
|
|
|
|
t.Fatalf("valid false, expected true")
|
|
|
|
}
|
|
|
|
if string(key) != "b" {
|
|
|
|
t.Fatalf("exepcted key b, got %s", key)
|
|
|
|
}
|
|
|
|
if string(val) != "val-b" {
|
|
|
|
t.Fatalf("expected value val-b, got %s", val)
|
|
|
|
}
|
|
|
|
|
|
|
|
it.Next()
|
|
|
|
key, val, valid = it.Current()
|
|
|
|
if !valid {
|
|
|
|
t.Fatalf("valid false, expected true")
|
|
|
|
}
|
|
|
|
if string(key) != "c" {
|
|
|
|
t.Fatalf("exepcted key c, got %s", key)
|
|
|
|
}
|
|
|
|
if string(val) != "val-c" {
|
|
|
|
t.Fatalf("expected value val-c, got %s", val)
|
|
|
|
}
|
|
|
|
|
|
|
|
it.Seek([]byte("i"))
|
|
|
|
key, val, valid = it.Current()
|
|
|
|
if !valid {
|
|
|
|
t.Fatalf("valid false, expected true")
|
|
|
|
}
|
|
|
|
if string(key) != "i" {
|
|
|
|
t.Fatalf("exepcted key i, got %s", key)
|
|
|
|
}
|
|
|
|
if string(val) != "val-i" {
|
|
|
|
t.Fatalf("expected value val-i, got %s", val)
|
|
|
|
}
|
|
|
|
|
|
|
|
it.Close()
|
|
|
|
}
|