aboutsummaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/testutil_test.go
blob: 25bf2b29f99310e6af6ab1532ccfc9cdf1621e87 (plain) (blame)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2014, Suryandaru Triandana <syndtr@gmail.com>
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package leveldb

import (
    . "github.com/onsi/gomega"

    "github.com/syndtr/goleveldb/leveldb/iterator"
    "github.com/syndtr/goleveldb/leveldb/opt"
    "github.com/syndtr/goleveldb/leveldb/testutil"
    "github.com/syndtr/goleveldb/leveldb/util"
)

type testingDB struct {
    *DB
    ro   *opt.ReadOptions
    wo   *opt.WriteOptions
    stor *testutil.Storage
}

func (t *testingDB) TestPut(key []byte, value []byte) error {
    return t.Put(key, value, t.wo)
}

func (t *testingDB) TestDelete(key []byte) error {
    return t.Delete(key, t.wo)
}

func (t *testingDB) TestGet(key []byte) (value []byte, err error) {
    return t.Get(key, t.ro)
}

func (t *testingDB) TestHas(key []byte) (ret bool, err error) {
    return t.Has(key, t.ro)
}

func (t *testingDB) TestNewIterator(slice *util.Range) iterator.Iterator {
    return t.NewIterator(slice, t.ro)
}

func (t *testingDB) TestClose() {
    err := t.Close()
    ExpectWithOffset(1, err).NotTo(HaveOccurred())
    err = t.stor.Close()
    ExpectWithOffset(1, err).NotTo(HaveOccurred())
}

func newTestingDB(o *opt.Options, ro *opt.ReadOptions, wo *opt.WriteOptions) *testingDB {
    stor := testutil.NewStorage()
    db, err := Open(stor, o)
    // FIXME: This may be called from outside It, which may cause panic.
    Expect(err).NotTo(HaveOccurred())
    return &testingDB{
        DB:   db,
        ro:   ro,
        wo:   wo,
        stor: stor,
    }
}