WithArgs doesn't work properly
glenshappy opened this issue · 1 comments
glenshappy commented
Hi, guys, i wrote one pice of code as below, but i couldn't use WithArgs like this:
mock.ExpectQuery(query2).WithArgs(122).WillReturnRows(rs2),so i have to use it like this:
query2:= "SELECT (.+) as count FROM payment p, purchase_order po WHERE p.order_id = po.id AND p.order_id = "+strconv.Itoa(orderId)+" ORDER BY p.payment_date DESC "
Is there anything wrong with this code?Thx
`
func TestOrderList(t *testing.T) {
t.Parallel()
orderModel := CreateOrderFactory(t)
defer db.Close()
var orderId = 122
rs1 := sqlmock.NewRows([]string{"id", "order_id","user_id"}).AddRow(12, orderId,133)
rs2 := sqlmock.NewRows([]string{"count"}).AddRow(1223)
query1 := "SELECT p.*, po.user_id FROM payment p, purchase_order po"
query2:= "SELECT (.+) as count FROM payment p, purchase_order po WHERE p.order_id = po.id AND p.order_id = "+strconv.Itoa(orderId)+" ORDER BY p.payment_date DESC "
mock.ExpectQuery(query1).WillReturnRows(rs1)
mock.ExpectQuery(query2).WillReturnRows(rs2)
count, l := orderModel.List(orderId, 1, -1, 12,11, "kijijiapi01@gmail.com", "d","d")
if err := mock.ExpectationsWereMet(); err != nil {
t.Fatalf("there were unfulfilled expectations: %s", err)
}
}
`
dolmen commented
Please post some example code working on the Go Playground. Here is a template.