mock.ExpectExec("UPDATE `users` SET `updated_at` = ?, `username` = ? WHERE (id = ?)").
WithArgs(time.Now(), newName, userId).
WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit()
err := UpdateUserNameById(newName, userId)
assert.Nil(t, err)
}
复制代码
运行测试后,会有下面的报错信息:
ExecQuery 'UPDATE `users` SET `updated_at` = ?, `username` = ? WHERE (id = ?)', arguments do not match: argument 0 expected [time.Time - 2022-05-08 18:13:08.23323 +0800 CST m=+0.003082084] does not match actual [time.Time - 2022-05-08 18:13:08.234134 +0800 CST m=+0.003986334]