-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrm_test.go
30 lines (24 loc) · 824 Bytes
/
rm_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
package main
import (
"testing"
"github.com/DATA-DOG/go-sqlmock"
)
func TestGetAllLists(t *testing.T) {
db, mock, err := sqlmock.New()
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}
defer db.Close()
mock.ExpectBegin()
mock.ExpectExec("UPDATE products").WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectExec("INSERT INTO product_viewers").WithArgs(2, 3).WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit()
// now we execute our method
// if err = recordStats(db, 2, 3); err != nil {
// t.Errorf("error was not expected while updating stats: %s", err)
// }
// we make sure that all expectations were met
// if err := mock.ExpectationsWereMet(); err != nil {
// t.Errorf("there were unfulfilled expectations: %s", err)
// }
}