-
Notifications
You must be signed in to change notification settings - Fork 0
/
torm_test.go
73 lines (62 loc) · 1.34 KB
/
torm_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
package torm
import (
"testing"
"github.com/pinnacles/torm/internal/test"
)
func TestRegister(t *testing.T) {
Register(test.TestSchema{})
if m, ok := metas["test"]; !ok {
t.Fatal("metas don't have a `test` key")
} else {
if m.TableName != "test" {
t.Error("m.TableName is not `test`")
}
ok := false
for _, f := range m.Fields {
if f == "foo" {
ok = true
}
}
if !ok {
t.Error("m.Fileds don't have `foo` key")
}
ok = false
for _, f := range m.Fields {
if f == "bar" {
ok = true
}
}
if ok {
t.Error("m.Fileds have `bar` key")
}
}
}
func TestVerboseLevelValid(t *testing.T) {
for _, lv := range []int{0, 1, 2, 3} {
VerboseLevel(lv)
}
}
func TestVerboseLevelInvalidNegative(t *testing.T) {
lv := -1
defer func() {
err := recover()
if err == nil {
t.Errorf("VerboseLevel(%d) don't panic", lv)
} else if err != "VerboseLevel is must be in range of 0 to 3" {
t.Errorf("VerboseLevel(%d) error message is not that was expected", lv)
}
}()
VerboseLevel(lv)
}
func TestVerboseLevelInvalidPositive(t *testing.T) {
lv := 4
defer func() {
err := recover()
if err == nil {
t.Errorf("VerboseLevel(%d) don't panic", lv)
} else if err != "VerboseLevel is must be in range of 0 to 3" {
t.Errorf("VerboseLevel(%d) error message is not that was expected", lv)
}
}()
VerboseLevel(lv)
}