-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable_insert2_test.go
More file actions
50 lines (42 loc) · 1.15 KB
/
table_insert2_test.go
File metadata and controls
50 lines (42 loc) · 1.15 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
package ldb
import (
"fmt"
"regexp"
"testing"
"github.com/DATA-DOG/go-sqlmock"
"github.com/stretchr/testify/assert"
)
func TestInsert2_mysql(t *testing.T) {
as := assert.New(t)
db, mock, err := sqlmock.New()
as.Nil(err, fmt.Sprintf("failed to open sqlmock database: %s", err))
engine := MustConnectMock(db, &MysqlConf{})
mock.ExpectExec(regexp.QuoteMeta("INSERT INTO t_user (id, name) VALUES (?, ?);")).
WithArgs(1, "tom").
WillReturnError(nil).
WillReturnResult(sqlmock.NewResult(0, 1))
var u = User{
Id: 1,
Name: "tom",
}
num, err := Insert(engine, u, E().ShowSql())
as.Nil(err)
as.Equal(int64(1), num, "num error")
}
func TestInsert2_pg(t *testing.T) {
as := assert.New(t)
db, mock, err := sqlmock.New()
as.Nil(err, fmt.Sprintf("failed to open sqlmock database: %s", err))
engine := MustConnectMock(db, &PgConf{})
mock.ExpectExec(regexp.QuoteMeta("INSERT INTO t_user (id, name) VALUES ($1, $2);")).
WithArgs(1, "tom").
WillReturnError(nil).
WillReturnResult(sqlmock.NewResult(0, 1))
var u = User{
Id: 1,
Name: "tom",
}
num, err := Insert(engine, u, E().ShowSql())
as.Nil(err)
as.Equal(int64(1), num, "num error")
}