1 // Copyright (c) 2014, Suryandaru Triandana <syndtr@gmail.com>
2 // All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file.
10 . "github.com/onsi/gomega"
12 "github.com/syndtr/goleveldb/leveldb/iterator"
13 "github.com/syndtr/goleveldb/leveldb/opt"
14 "github.com/syndtr/goleveldb/leveldb/testutil"
15 "github.com/syndtr/goleveldb/leveldb/util"
18 type testingDB struct {
22 stor *testutil.Storage
25 func (t *testingDB) TestPut(key []byte, value []byte) error {
26 return t.Put(key, value, t.wo)
29 func (t *testingDB) TestDelete(key []byte) error {
30 return t.Delete(key, t.wo)
33 func (t *testingDB) TestGet(key []byte) (value []byte, err error) {
34 return t.Get(key, t.ro)
37 func (t *testingDB) TestHas(key []byte) (ret bool, err error) {
38 return t.Has(key, t.ro)
41 func (t *testingDB) TestNewIterator(slice *util.Range) iterator.Iterator {
42 return t.NewIterator(slice, t.ro)
45 func (t *testingDB) TestClose() {
47 ExpectWithOffset(1, err).NotTo(HaveOccurred())
49 ExpectWithOffset(1, err).NotTo(HaveOccurred())
52 func newTestingDB(o *opt.Options, ro *opt.ReadOptions, wo *opt.WriteOptions) *testingDB {
53 stor := testutil.NewStorage()
54 db, err := Open(stor, o)
55 // FIXME: This may be called from outside It, which may cause panic.
56 Expect(err).NotTo(HaveOccurred())
65 type testingTransaction struct {
71 func (t *testingTransaction) TestPut(key []byte, value []byte) error {
72 return t.Put(key, value, t.wo)
75 func (t *testingTransaction) TestDelete(key []byte) error {
76 return t.Delete(key, t.wo)
79 func (t *testingTransaction) TestGet(key []byte) (value []byte, err error) {
80 return t.Get(key, t.ro)
83 func (t *testingTransaction) TestHas(key []byte) (ret bool, err error) {
84 return t.Has(key, t.ro)
87 func (t *testingTransaction) TestNewIterator(slice *util.Range) iterator.Iterator {
88 return t.NewIterator(slice, t.ro)
91 func (t *testingTransaction) TestClose() {}