如何使用golang go-sqlmock sqlmock一个空集

时间:2017-05-02 15:31:26

标签: mysql

我想测试一些SQL,如:

select name from user where uid = ?

这没关系,我可以这样嘲笑它:

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

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

但是我想模拟用户表没有这个uid的测试 - select会返回一个空集

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

mysql>

我如何模拟空表?

1 个答案:

答案 0 :(得分:0)

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