forked from c9s/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_test.go
73 lines (60 loc) · 1.31 KB
/
load_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 gatsby
import "testing"
func resultSuccess(t *testing.T, res *Result) *Result {
if res.Error != nil {
if res.Sql != "" {
t.Log(res.Sql)
}
t.Fatal(res.Error)
}
return res
}
func BenchmarkLoad(b *testing.B) {
var db = openDB()
staff := Staff{Name: "John", Gender: "m", Phone: "1234567"}
res := Create(db, &staff, DriverPg)
b.ResetTimer()
for i := 0; i < b.N; i++ {
var staff2 = Staff{}
Load(db, &staff2, res.Id)
}
}
func TestLoad(t *testing.T) {
var db = openDB()
staff := Staff{Name: "John", Gender: "m", Phone: "1234567"}
r := resultSuccess(t, Create(db, &staff, DriverPg))
t.Logf("staff id: %d", r.Id)
staff2 := Staff{}
r = Load(db, &staff2, r.Id)
t.Log(r.Sql)
if r.Error != nil {
t.Fatal(r.Error)
}
if staff2.Id == 0 {
t.Fatal("Can not load record")
}
if staff2.Phone != "1234567" {
t.Fatal("Can not load record")
}
staff3 := Staff{}
res := resultSuccess(t, LoadByCols(db, &staff3, map[string]interface{}{
"Phone": "1234567",
}))
if staff3.Id == 0 {
t.Fatal(res.Error)
}
if staff3.Phone != "1234567" {
t.Fatal(res.Error)
}
staff4 := Staff{}
res = resultSuccess(t, LoadByCols(db, &staff4, WhereMap{
"Phone": "1234567",
}))
if staff4.Id == 0 {
t.Fatal(res.Error)
}
if staff4.Phone != "1234567" {
t.Fatal(res.Error)
}
resultSuccess(t, Delete(db, &staff))
}