-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurd_test.go
More file actions
89 lines (78 loc) · 1.39 KB
/
curd_test.go
File metadata and controls
89 lines (78 loc) · 1.39 KB
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
package curd
import (
"testing"
"github.com/stretchr/testify/assert"
)
var (
db = NewDB(
"test",
"test",
"",
"3306",
"test",
)
)
type Order struct {
ID int64 `db:"id"`
Status int `db:"status"`
}
func TestSelect(t *testing.T) {
ins := make([]*Order, 0)
err := db.R(
"order",
[]string{"id", "status"},
map[string]interface{}{"id": 1},
&ins,
)
assert.Nil(t, err)
assert.Equal(t,
[]*Order{
&Order{ID: 1, Status: 3},
}, ins)
}
func TestSelectPage(t *testing.T) {
ins := make([]*Order, 0)
err := db.RPage(
"order",
1, 5,
[]string{"id", "status"},
map[string]interface{}{"status": 2},
&ins,
)
assert.Nil(t, err)
assert.Equal(t, 5, len(ins))
ins = make([]*Order, 0)
err = db.RPage(
"order",
1, 10,
[]string{"id", "status"},
map[string]interface{}{"status": 2},
&ins,
)
assert.Nil(t, err)
assert.Equal(t, 10, len(ins))
}
func TestInsert(t *testing.T) {
oldCount := 0
err := db.Get(&oldCount, "select COUNT(*) FROM `user`")
assert.Nil(t, err)
_, err = db.C(
"user",
map[string]interface{}{
"name": "314156",
},
)
assert.Nil(t, err)
newCount := 0
_ = db.Get(&newCount, "select COUNT(*) FROM `user`")
assert.Equal(t, newCount, oldCount+1)
_, err = db.D(
"user",
map[string]interface{}{
"name": "314156",
},
)
assert.Nil(t, err)
_ = db.Get(&newCount, "select COUNT(*) FROM `user`")
assert.Equal(t, newCount, oldCount)
}