Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WithArgs doesn't work properly #275

Open
glenshappy opened this issue Oct 28, 2021 · 1 comment
Open

WithArgs doesn't work properly #275

glenshappy opened this issue Oct 28, 2021 · 1 comment

Comments

@glenshappy
Copy link

glenshappy commented Oct 28, 2021

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
Copy link
Contributor

dolmen commented Apr 22, 2022

Please post some example code working on the Go Playground. Here is a template.

@Ghvstcode Ghvstcode added needs-discussion Needs some discussion to figure out what direction we want to go in the case of the specific issue bug needs-investigation and removed needs-discussion Needs some discussion to figure out what direction we want to go in the case of the specific issue labels Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants