DATA-DOG / go-sqlmock

Sql mock driver for golang to test database interactions
Other
6.02k stars 406 forks source link

set expectations to run multiple times #257

Closed yashschandra closed 2 months ago

yashschandra commented 3 years ago

Added new "times" method which can set expectation to run same query multiple number of times. eg.

mock.ExpectExec("DELETE FROM users"). WillReturnResult(NewResult(1, 1)).Times(3) will expect same query 3 times

yashschandra commented 3 years ago

@l3pp4rd few weeks back i required this at my work place, do you think it is good enough to include ?

l3pp4rd commented 3 years ago

well, this is something that I do not like. the reasons are:

  1. it will force sqlmock to lose the strict ordered matching.
  2. it adds more than needed to the library
  3. it is simple enough to mock a call few times in test. for example creating a function variable in test to just append the same expectation to mock, but do not lose the strict ordered matching.
  4. I do not want to add interfaces to the library, which only makes some things to be done easier for users, because this is the same as building the framework, in the end it becomes unmanageable.