-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathdb_test.go
64 lines (53 loc) · 1.09 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
package gcse
import (
"testing"
"github.com/golangplus/testing/assert"
"github.com/daviddengcn/go-villa"
)
func TestMemDB_Bug_Sync(t *testing.T) {
path := villa.Path(".").Join("testmemdb.gob")
if path.Exists() {
path.Remove()
}
db := NewMemDB(".", "testmemdb")
db.Put("s", 1)
err := db.Sync()
if err != nil {
t.Error(err)
}
assert.Equal(t, "Exists", path.Exists(), true)
if err := path.Remove(); err != nil {
t.Error(err)
}
assert.Equal(t, "Exists", path.Exists(), false)
//if err := db.Load(); err != nil {
// t.Error(err)
//}
}
func TestMemDB_Recover(t *testing.T) {
path := villa.Path(".").Join("testmemdb.gob")
if path.Exists() {
path.Remove()
}
db := NewMemDB(".", "testmemdb")
db.Put("s", 1)
if err := db.Sync(); err != nil {
t.Error(err)
return
}
if err := path.Rename(path + ".new"); err != nil {
t.Error(err)
return
}
// Now in the status of fn.new exists, fn not exist
if err := db.Load(); err != nil {
t.Error(err)
return
}
var vl int
if ok := db.Get("s", &vl); !ok {
t.Error("Recover failed!")
return
}
assert.Equal(t, "vl", vl, 1)
}