-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnative_exec_test.go
More file actions
41 lines (33 loc) · 1.02 KB
/
native_exec_test.go
File metadata and controls
41 lines (33 loc) · 1.02 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
package ldb
import (
"github.com/DATA-DOG/go-sqlmock"
"github.com/stretchr/testify/assert"
"testing"
)
func TestExec_del(t *testing.T) {
as := assert.New(t)
db, mock, err := sqlmock.New()
as.Nil(err, "new sqlmock error")
engine := MustConnectMock(db, &PgConf{})
mock.ExpectExec("delete from user where id = ? ").
WithArgs(1).
WillReturnError(nil).
WillReturnResult(sqlmock.NewResult(0, 1))
num, err := Exec(engine, "delete from user where id = ?", 1)
as.Nil(err)
as.Equal(int64(1), num, "num error")
}
func TestExec_update(t *testing.T) {
as := assert.New(t)
db, mock, err := sqlmock.New()
as.Nil(err, "new sqlmock error")
engine := MustConnectMock(db, &PgConf{})
mock.ExpectExec("update user set name = 'kk' where id = ? ").
WithArgs(1).
WillReturnError(nil).
WillReturnResult(sqlmock.NewResult(0, 1))
num, err := Exec(engine, "update user set name = 'kk' where id = ? ", 1)
as.Nil(err)
as.Equal(int64(1), num, "num error")
as.Nil(mock.ExpectationsWereMet(), "we make sure that all expectations were met")
}