forked from szferi/gomdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env_test.go
79 lines (73 loc) · 1.53 KB
/
env_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
package mdb
import (
"io/ioutil"
"os"
"testing"
)
func TestEnvOpen(t *testing.T) {
env, err := NewEnv()
if err != nil {
t.Errorf("Cannot create enviroment: %s", err)
}
err = env.Open("adsjgfadsfjg", 0, 0664)
if err == nil {
t.Errorf("should not be able to open")
}
path, err := ioutil.TempDir("/tmp", "mdb_test")
if err != nil {
t.Errorf("Cannot create temporary directory")
}
err = os.MkdirAll(path, 0770)
if err != nil {
t.Errorf("Cannot create directory: %s", path)
}
err = env.Open(path, 0, 0664)
if err != nil {
t.Errorf("Cannot open environment: %s", err)
}
err = env.Close()
if err != nil {
t.Errorf("Error during close of environment: %s", err)
}
// clean up
os.RemoveAll(path)
}
func setup(t *testing.T) *Env {
env, err := NewEnv()
if err != nil {
t.Errorf("Cannot create enviroment: %s", err)
}
path, err := ioutil.TempDir("/tmp", "mdb_test")
if err != nil {
t.Errorf("Cannot create temporary directory")
}
err = os.MkdirAll(path, 0770)
if err != nil {
t.Errorf("Cannot create directory: %s", path)
}
err = env.Open(path, 0, 0664)
if err != nil {
t.Errorf("Cannot open environment: %s", err)
}
return env
}
func clean(env *Env, t *testing.T) {
path, err := env.Path()
if err != nil {
t.Errorf("Cannot get path")
}
if path == "" {
t.Errorf("Invalid path")
}
t.Logf("Env path: %s", path)
err = env.Close()
if err != nil {
t.Errorf("Error during close of environment: %s", err)
}
// clean up
os.RemoveAll(path)
}
func TestEnvCopy(t *testing.T) {
env := setup(t)
clean(env, t)
}