-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathboltdb_test.go
More file actions
46 lines (37 loc) · 923 Bytes
/
boltdb_test.go
File metadata and controls
46 lines (37 loc) · 923 Bytes
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
package boltdb
import (
"os"
"testing"
bolt "go.etcd.io/bbolt"
)
func TestConfigureBoltDb(t *testing.T) {
tests := []struct {
name string
dbPath string
expectedPath string
}{
{"happy configuration BoltDB with dbPath", "database/webhooks.db", "database/webhooks.db"},
{"happy configuration BoltDB with empty dbPath", "", "/server/database/webhooks.db"},
}
savedOpen := open
open = func(path string) (*bolt.DB, error) {
return nil, nil
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
boltdb, err := NewBoltDb(test.dbPath)
if err != nil {
t.Errorf("Unexpected error: %v", err)
return
}
configuredPath := boltdb.DbPath
if test.expectedPath != configuredPath {
t.Errorf("paths do not match, expected: %s, got: %s", test.expectedPath, configuredPath)
}
})
}
defer func() {
os.RemoveAll("database/")
open = savedOpen
}()
}