h2non / gock

HTTP traffic mocking and testing made easy in Go ༼ʘ̚ل͜ʘ̚༽
https://pkg.go.dev/github.com/h2non/gock
MIT License
2.04k stars 106 forks source link

Add callback functionality #116

Open roytouw7 opened 4 months ago

roytouw7 commented 4 months ago

Using Mockery there is the option to register a callback function which will get triggered upon hitting the mock, in our unit tests we use this to have the unit test wait for some mocks to get hit which happen in a detached go routine, this way we do not have to add any arbitrary time.Sleep in the tests. The Mockery example is listed below, it would be nice if this would also be possible in Gock.

test.reservationEmailService.
  On("SendConfirmationEmail", mock.Anything, &reservationModels.ConfirmationRequest{GUID: "123456", Language: ""}).
  Return(fmt.Errorf("email error")).
  Once().
  Run(callback)