-
Notifications
You must be signed in to change notification settings - Fork 39
/
mapper_test.go
109 lines (89 loc) · 1.71 KB
/
mapper_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package gosql
import (
"strconv"
"testing"
)
func mapInsert(t *testing.T, id int64) int64 {
id, err := Table("users").Create(map[string]interface{}{
"id": id,
"name": "test" + strconv.Itoa(int(id)),
"status": 1,
"created_at": "2018-07-11 11:58:21",
"updated_at": "2018-07-11 11:58:21",
})
if err != nil {
t.Error(err)
}
if id <= 0 {
t.Error("map insert error")
}
return id
}
func TestMapper_Create(t *testing.T) {
RunWithSchema(t, func(t *testing.T) {
mapInsert(t, 1)
})
}
func TestMapper_Update(t *testing.T) {
RunWithSchema(t, func(t *testing.T) {
id := mapInsert(t, 1)
affected, err := Table("users").Where("id = ?", id).Update(map[string]interface{}{
"name": "fifsky",
})
if err != nil {
t.Error(err)
}
if affected <= 0 {
t.Error("map update error")
}
})
}
func TestMapper_Delete(t *testing.T) {
RunWithSchema(t, func(t *testing.T) {
{
id := mapInsert(t, 1)
affected, err := Table("users").Where("id = ?", id).Delete()
if err != nil {
t.Error(err)
}
if affected <= 0 {
t.Error("map delete error")
}
}
{
mapInsert(t, 2)
affected, err := Table("users").Delete()
if err != nil {
t.Error(err)
}
if affected <= 0 {
t.Error("map delete error")
}
}
})
}
func TestMapper_Count(t *testing.T) {
RunWithSchema(t, func(t *testing.T) {
{
id := mapInsert(t, 1)
num, err := Table("users").Where("id = ?", id).Count()
if err != nil {
t.Error(err)
}
if num != 1 {
t.Error("map count error")
}
}
{
mapInsert(t, 2)
mapInsert(t, 3)
num, err := Table("users").Count()
if err != nil {
t.Error(err)
}
if num <= 0 {
t.Error("map count error")
}
}
})
}