github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/syndtr/goleveldb/leveldb/testutil_test.go (about)

     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  
     7  package leveldb
     8  
     9  import (
    10  	. "github.com/insionng/yougam/libraries/onsi/gomega"
    11  
    12  	"github.com/insionng/yougam/libraries/syndtr/goleveldb/leveldb/iterator"
    13  	"github.com/insionng/yougam/libraries/syndtr/goleveldb/leveldb/opt"
    14  	"github.com/insionng/yougam/libraries/syndtr/goleveldb/leveldb/testutil"
    15  	"github.com/insionng/yougam/libraries/syndtr/goleveldb/leveldb/util"
    16  )
    17  
    18  type testingDB struct {
    19  	*DB
    20  	ro   *opt.ReadOptions
    21  	wo   *opt.WriteOptions
    22  	stor *testutil.Storage
    23  }
    24  
    25  func (t *testingDB) TestPut(key []byte, value []byte) error {
    26  	return t.Put(key, value, t.wo)
    27  }
    28  
    29  func (t *testingDB) TestDelete(key []byte) error {
    30  	return t.Delete(key, t.wo)
    31  }
    32  
    33  func (t *testingDB) TestGet(key []byte) (value []byte, err error) {
    34  	return t.Get(key, t.ro)
    35  }
    36  
    37  func (t *testingDB) TestHas(key []byte) (ret bool, err error) {
    38  	return t.Has(key, t.ro)
    39  }
    40  
    41  func (t *testingDB) TestNewIterator(slice *util.Range) iterator.Iterator {
    42  	return t.NewIterator(slice, t.ro)
    43  }
    44  
    45  func (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  
    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())
    57  	return &testingDB{
    58  		DB:   db,
    59  		ro:   ro,
    60  		wo:   wo,
    61  		stor: stor,
    62  	}
    63  }
    64  
    65  type testingTransaction struct {
    66  	*Transaction
    67  	ro *opt.ReadOptions
    68  	wo *opt.WriteOptions
    69  }
    70  
    71  func (t *testingTransaction) TestPut(key []byte, value []byte) error {
    72  	return t.Put(key, value, t.wo)
    73  }
    74  
    75  func (t *testingTransaction) TestDelete(key []byte) error {
    76  	return t.Delete(key, t.wo)
    77  }
    78  
    79  func (t *testingTransaction) TestGet(key []byte) (value []byte, err error) {
    80  	return t.Get(key, t.ro)
    81  }
    82  
    83  func (t *testingTransaction) TestHas(key []byte) (ret bool, err error) {
    84  	return t.Has(key, t.ro)
    85  }
    86  
    87  func (t *testingTransaction) TestNewIterator(slice *util.Range) iterator.Iterator {
    88  	return t.NewIterator(slice, t.ro)
    89  }
    90  
    91  func (t *testingTransaction) TestClose() {}