-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable_insert6_test.go
More file actions
51 lines (43 loc) · 1.16 KB
/
table_insert6_test.go
File metadata and controls
51 lines (43 loc) · 1.16 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
package ldb
import (
"fmt"
"regexp"
"testing"
"github.com/DATA-DOG/go-sqlmock"
"github.com/stretchr/testify/assert"
)
func TestInsert6_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 x_user (name) VALUES (?);")).
WithArgs("tom").
WillReturnError(nil).
WillReturnResult(sqlmock.NewResult(0, 1))
var u = User{
Id: 0,
Name: "tom",
}
num, err := Insert(engine, u, E().ShowSql().TableName("x_user"))
as.Nil(err)
as.Equal(int64(1), num, "num error")
}
func TestInsert6_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 x_user (id) VALUES ($1);")).
WithArgs(1).
WillReturnError(nil).
WillReturnResult(sqlmock.NewResult(0, 1))
var u = struct {
Id int64
}{
Id: 1,
}
num, err := Insert(engine, u, E().ShowSql().TableName("x_user"))
as.Nil(err)
as.Equal(int64(1), num, "num error")
}