9

I want to test some SQL like:

select name from user where uid = ?

This is ok, I can mock it like this way:

rows := sqlmock.NewRows([]string{“name"}).AddRow(“info")

did = "1234"
mock.ExpectPrepare(“select name from user where uid = ?").ExpectQuery().
       WithArgs(uid).
       WillReturnRows(rows)

But I want to mock the testing in which the user table does not have this uid — the select will return a Empty set

mysql> select * from user where uid = “887";
Empty set (0.00 sec)

mysql>

How can I mock an empty table?

1 Answer 1

14
rows := sqlmock.NewRows([]string{“name"})

not addRow

Sign up to request clarification or add additional context in comments.

1 Comment

You could also not assign the NewRows() to an unused variable rows

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.