go-sqlmock icon indicating copy to clipboard operation
go-sqlmock copied to clipboard

set expectations to run multiple times

Open yashschandra opened this issue 4 years ago • 2 comments
trafficstars

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 avatar Mar 11 '21 17:03 yashschandra

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

yashschandra avatar Mar 12 '21 13:03 yashschandra

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.

l3pp4rd avatar Apr 02 '21 06:04 l3pp4rd