forked from abdullin/cellar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
options_test.go
54 lines (41 loc) · 1.3 KB
/
options_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
package cellar
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestWithCipher(t *testing.T) {
aes := NewAES(defaultEncryptionKey)
db, err := New(dbDir, WithNoFileLock, WithReadOnly, WithCipher(aes))
require.NoError(t, err)
defer db.Close()
assert.Equal(t, aes, db.cipher)
}
func TestWithLogger(t *testing.T) {
logger := defaultLogger()
db, err := New(dbDir, WithNoFileLock, WithReadOnly, WithLogger(logger))
require.NoError(t, err)
defer db.Close()
assert.Equal(t, logger, db.logger)
}
func TestWithMetaDB(t *testing.T) {
mdb := &BoltMetaDB{}
db, err := New(dbDir, WithNoFileLock, WithReadOnly, WithMetaDB(mdb))
require.NoError(t, err)
assert.Equal(t, mdb, db.meta)
}
func TestWithNoFileLock(t *testing.T) {
mdb := &BoltMetaDB{}
// WithMetaDB is provided because by default boltdb is used, which is
// rw once
_, err := New(dbDir, WithNoFileLock, WithReadOnly, WithMetaDB(mdb))
require.NoError(t, err)
_, err = New(dbDir, WithNoFileLock, WithReadOnly, WithMetaDB(mdb))
require.NoError(t, err)
// first db with file lock should work
_, err = New(dbDir, WithReadOnly, WithMetaDB(mdb))
require.NoError(t, err)
// second should fail because there now is a file lock
_, err = New(dbDir, WithReadOnly, WithMetaDB(mdb))
assert.Error(t, err)
}