This repository has been archived by the owner on Apr 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
environment_test.go
82 lines (67 loc) · 1.77 KB
/
environment_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
package berkeleydb_test
import (
"os"
"testing"
"github.com/jsimonetti/berkeleydb"
)
const TestDirectory = "./TEST_ENV"
func TestNewEnvironment(t *testing.T) {
_, err := os.Stat(TestDirectory)
if err != nil && os.IsNotExist(err) {
e := os.Mkdir(TestDirectory, os.ModeDir|os.ModePerm)
if e != nil {
t.Fatal("Failed to create directory: %s", e)
}
}
_, err = berkeleydb.NewEnvironment()
if err != nil {
t.Error("Expected environment, got %s", err)
}
}
func TestOpenEnvironment(t *testing.T) {
env, _ := berkeleydb.NewEnvironment()
err := env.Open(TestDirectory, berkeleydb.DbCreate|berkeleydb.DbInitMpool, 0)
if err != nil {
t.Error("Expected to open DB, got %s", err)
}
err = env.Close()
if err != nil {
t.Error("Expected to close DB, got %s", err)
}
}
func TestOpenDBInEnvironment(t *testing.T) {
env, _ := berkeleydb.NewEnvironment()
err := env.Open(TestDirectory, berkeleydb.DbCreate|berkeleydb.DbInitMpool, 0755)
if err != nil {
t.Error("Expected to open DB, got ", err)
return
}
// Now create, open, and close a DB
db, err := berkeleydb.NewDBInEnvironment(env)
if err != nil {
t.Error("Expected to create new DB: ", err)
}
err = db.Open(TestFilename, berkeleydb.DbBtree, berkeleydb.DbCreate)
if err != nil {
t.Error("Expected to open DB, got ", err)
}
// Test that the DB file was actually created.
_, err = os.Stat(TestDirectory + "/" + TestFilename)
if err != nil {
t.Error("Expected to stat .db, got ", err)
}
err = db.Close()
if err != nil {
t.Error("Expected to close the DB, got ", err)
}
err = env.Close()
if err != nil {
t.Error("Expected to close DB, got %s", err)
}
}
func TestTeardown(t *testing.T) {
err := os.RemoveAll(TestDirectory)
if err != nil {
t.Fatal("Expected to remove fixtures, got %s", err)
}
}