1// Copyright (c) 2014, Suryandaru Triandana <syndtr@gmail.com> 2// All rights reserved. 3// 4// Use of this source code is governed by a BSD-style license that can be 5// found in the LICENSE file. 6 7package leveldb 8 9import ( 10 . "github.com/onsi/gomega" 11 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" 16) 17 18type testingDB struct { 19 *DB 20 ro *opt.ReadOptions 21 wo *opt.WriteOptions 22 stor *testutil.Storage 23} 24 25func (t *testingDB) TestPut(key []byte, value []byte) error { 26 return t.Put(key, value, t.wo) 27} 28 29func (t *testingDB) TestDelete(key []byte) error { 30 return t.Delete(key, t.wo) 31} 32 33func (t *testingDB) TestGet(key []byte) (value []byte, err error) { 34 return t.Get(key, t.ro) 35} 36 37func (t *testingDB) TestHas(key []byte) (ret bool, err error) { 38 return t.Has(key, t.ro) 39} 40 41func (t *testingDB) TestNewIterator(slice *util.Range) iterator.Iterator { 42 return t.NewIterator(slice, t.ro) 43} 44 45func (t *testingDB) TestClose() { 46 err := t.Close() 47 ExpectWithOffset(1, err).NotTo(HaveOccurred()) 48 err = t.stor.Close() 49 ExpectWithOffset(1, err).NotTo(HaveOccurred()) 50} 51 52func 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()) 57 return &testingDB{ 58 DB: db, 59 ro: ro, 60 wo: wo, 61 stor: stor, 62 } 63} 64 65type testingTransaction struct { 66 *Transaction 67 ro *opt.ReadOptions 68 wo *opt.WriteOptions 69} 70 71func (t *testingTransaction) TestPut(key []byte, value []byte) error { 72 return t.Put(key, value, t.wo) 73} 74 75func (t *testingTransaction) TestDelete(key []byte) error { 76 return t.Delete(key, t.wo) 77} 78 79func (t *testingTransaction) TestGet(key []byte) (value []byte, err error) { 80 return t.Get(key, t.ro) 81} 82 83func (t *testingTransaction) TestHas(key []byte) (ret bool, err error) { 84 return t.Has(key, t.ro) 85} 86 87func (t *testingTransaction) TestNewIterator(slice *util.Range) iterator.Iterator { 88 return t.NewIterator(slice, t.ro) 89} 90 91func (t *testingTransaction) TestClose() {} 92