-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcete_test.go
85 lines (64 loc) · 1.43 KB
/
cete_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
package cete
import (
"io/ioutil"
"log"
"os"
"testing"
)
func init() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
}
func panicNotNil(err error) {
if err != nil {
panic(err)
}
}
func TestBasic(t *testing.T) {
if testing.Short() {
t.Parallel()
}
dir, err := ioutil.TempDir("", "cete_")
panicNotNil(err)
t.Log("testing directory:", dir)
defer func() {
if !t.Failed() {
os.RemoveAll(dir)
}
}()
db, err := Open(dir + "/data")
panicNotNil(err)
defer db.Close()
err = db.NewTable("testing")
panicNotNil(err)
if db.Table("does not exist") != nil {
t.Fatal("table should not exist, but does")
}
if db.Table("testing") == nil {
t.Fatal("testing should exist but, it doesn't")
}
db.Table("testing").Set("bob", "hello")
err = db.Table("testing").Set("bob", "something", 1000)
if err != ErrCounterChanged {
t.Fatal("error should be ErrCounterChanged, but isn't")
}
var result string
_, err = db.Table("testing").Get("bob", &result)
panicNotNil(err)
if result != "hello" {
t.Fatal("result should be hello, but isn't")
}
err = db.Table("testing").Delete("bob")
panicNotNil(err)
_, err = db.Table("testing").Get("bob", &result)
if err != ErrNotFound {
t.Fatal("err should be ErrNotFound, but isn't")
}
err = db.Table("testing").Drop()
panicNotNil(err)
if db.Table("testing") != nil {
t.Fatal("testing should be nil, but isn't")
}
db.Close()
db, err = Open(dir + "/data")
panicNotNil(err)
}