forked from tecbot/gorocksdb
-
Notifications
You must be signed in to change notification settings - Fork 2
/
slice_transform_test.go
45 lines (37 loc) · 1.27 KB
/
slice_transform_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package rdb
import (
"testing"
"github.com/facebookgo/ensure"
)
func TestSliceTransform(t *testing.T) {
db := newTestDB(t, "TestSliceTransform", func(opts *Options) {
opts.SetPrefixExtractor(&testSliceTransform{})
})
defer db.Close()
wo := NewDefaultWriteOptions()
ensure.Nil(t, db.Put(wo, []byte("foo1"), []byte("foo")))
ensure.Nil(t, db.Put(wo, []byte("foo2"), []byte("foo")))
ensure.Nil(t, db.Put(wo, []byte("bar1"), []byte("bar")))
iter := db.NewIterator(NewDefaultReadOptions())
defer iter.Close()
prefix := []byte("foo")
numFound := 0
for iter.Seek(prefix); iter.ValidForPrefix(prefix); iter.Next() {
numFound++
}
ensure.Nil(t, iter.Err())
ensure.DeepEqual(t, numFound, 2)
}
func TestFixedPrefixTransformOpen(t *testing.T) {
db := newTestDB(t, "TestFixedPrefixTransformOpen", func(opts *Options) {
opts.SetPrefixExtractor(NewFixedPrefixTransform(3))
})
defer db.Close()
}
type testSliceTransform struct {
initiated bool
}
func (st *testSliceTransform) Name() string { return "gorocksdb.test" }
func (st *testSliceTransform) Transform(src []byte) []byte { return src[0:3] }
func (st *testSliceTransform) InDomain(src []byte) bool { return len(src) >= 3 }
func (st *testSliceTransform) InRange(src []byte) bool { return len(src) == 3 }