-
Notifications
You must be signed in to change notification settings - Fork 5
/
db_test.go
75 lines (57 loc) · 1.8 KB
/
db_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
package tormenta
import (
"os"
"testing"
)
func Test_Open_ValidDirectory(t *testing.T) {
testName := "Testing opening Torment DB connection with a valid directory"
dir := "data/testing"
// Create a connection to a test DB
db, err := OpenWithOptions(dir, DefaultOptions)
defer db.Close()
if err != nil {
t.Errorf("%s. Failed to open connection with error %v", testName, err)
}
if db == nil {
t.Errorf("%s. Failed to open connection. DB is nil", testName)
}
// Check the directory exists
if _, err := os.Stat(dir); os.IsNotExist(err) {
t.Errorf("%s. Failed to create Torment data directory", testName)
}
}
func Test_Close(t *testing.T) {
testName := "Testing closing TormentaDB connection"
db, _ := OpenWithOptions("data/test", DefaultOptions)
err := db.Close()
if err != nil {
t.Errorf("%s. Failed to close connection with error: %v", testName, err)
}
}
func Test_Open_InvalidDirectory(t *testing.T) {
testName := "Testing opening Torment DB connection with an invalid directory"
// Create a connection to a test DB
db, err := OpenWithOptions("", DefaultOptions)
if err == nil {
t.Errorf("%s. Should have returned an error but did not", testName)
}
if db != nil {
t.Errorf("%s. Should have returned a nil connection but did not", testName)
}
}
func Test_Open_Test(t *testing.T) {
testName := "Testing opening Torment DB with a blank DB"
dir := "data/test"
// Create a connection to a test DB
db, err := OpenTestWithOptions(dir, DefaultOptions)
if err != nil {
t.Errorf("%s. Failed to open connection with error %v", testName, err)
}
if db == nil {
t.Errorf("%s. Failed to open connection. DB is nil", testName)
}
// Check the directory exists
if _, err := os.Stat(testDirectory(dir)); os.IsNotExist(err) {
t.Errorf("%s. Failed to create Torment data directory", testName)
}
}