我想测试一些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>
我如何模拟空表?
答案 0 :(得分:0)
rows:= sqlmock.NewRows([] string {“name"}) 不是addRow