-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbdodb_test.go
111 lines (91 loc) · 2.05 KB
/
bdodb_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package bdodb
import "os"
import "testing"
import "github.com/blevesearch/bleve"
import "github.com/blevesearch/bleve/index/upsidedown"
func cleanupDb(t *testing.T, path string) {
err := os.RemoveAll(path)
if err != nil {
t.Fatal(err)
}
}
func TestBleveIndex(t *testing.T) {
dbPath := "/tmp/test_bdodb"
defer cleanupDb(t, dbPath)
index, err := BleveIndex(dbPath, bleve.NewIndexMapping(), upsidedown.Name, nil)
if err != nil {
t.Errorf("%v", err)
return
}
if index == nil {
t.Error("Failed to create bleve index")
}
}
func TestBleveIndexWithEncryptionEnabled(t *testing.T) {
dbPath := "/tmp/test_bdodb_encrypted"
encryptionKey := []byte("67356274875244489356392574264952")
defer cleanupDb(t, dbPath)
{
// create index if not exists
index, err := BleveIndex(dbPath, bleve.NewIndexMapping(), upsidedown.Name, map[string]interface{}{
"BdodbConfig": Config{
EncryptionKey: encryptionKey,
Logger: nil,
},
})
if err != nil {
t.Errorf("%v", err)
return
}
if index == nil {
t.Error("Failed to create bleve index")
}
err = index.Close()
if err != nil {
t.Errorf("%v", err)
return
}
}
// index file should already exists now open it
{
index, err := BleveIndex(dbPath, bleve.NewIndexMapping(), upsidedown.Name, map[string]interface{}{
"BdodbConfig": Config{
EncryptionKey: encryptionKey,
Logger: nil,
},
})
if err != nil {
t.Errorf("%v", err)
return
}
if index == nil {
t.Error("Failed to create bleve index")
}
err = index.Close()
if err != nil {
t.Errorf("%v", err)
return
}
}
// index file should already exists now open it using config pointer
{
index, err := BleveIndex(dbPath, bleve.NewIndexMapping(), upsidedown.Name, map[string]interface{}{
"BdodbConfig": &Config{
EncryptionKey: encryptionKey,
Logger: nil,
},
})
if err != nil {
t.Errorf("%v", err)
return
}
if index == nil {
t.Error("Failed to create bleve index")
}
err = index.Close()
if err != nil {
t.Errorf("%v", err)
return
}
}
}