-
Notifications
You must be signed in to change notification settings - Fork 51
/
goleveldb_test.go
56 lines (47 loc) · 1.31 KB
/
goleveldb_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
46
47
48
49
50
51
52
53
54
55
56
package db
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/syndtr/goleveldb/leveldb/opt"
)
func TestGoLevelDBNewGoLevelDB(t *testing.T) {
name := fmt.Sprintf("test_%x", randStr(12))
defer cleanupDBDir("", name)
// Test we can't open the db twice for writing
wr1, err := NewGoLevelDB(name, "")
require.Nil(t, err)
_, err = NewGoLevelDB(name, "")
require.NotNil(t, err)
err = wr1.Close() // Close the db to release the lock
require.Nil(t, err)
// Test we can open the db twice for reading only
ro1, err := NewGoLevelDBWithOpts(name, "", &opt.Options{ReadOnly: true})
require.Nil(t, err)
defer ro1.Close()
ro2, err := NewGoLevelDBWithOpts(name, "", &opt.Options{ReadOnly: true})
require.Nil(t, err)
defer ro2.Close()
}
func BenchmarkGoLevelDBRandomReadsWrites(b *testing.B) {
name := fmt.Sprintf("test_%x", randStr(12))
db, err := NewGoLevelDB(name, "")
if err != nil {
b.Fatal(err)
}
defer func() {
err = db.Close()
require.NoError(b, err)
cleanupDBDir("", name)
}()
benchmarkRandomReadsWrites(b, db)
}
func TestGoLevelDBBackend(t *testing.T) {
name := fmt.Sprintf("test_%x", randStr(12))
db, err := NewDB(name, GoLevelDBBackend, "")
require.NoError(t, err)
defer cleanupDBDir("", name)
_, ok := db.(*GoLevelDB)
assert.True(t, ok)
}