You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As for go1.17 and below, the function can just be:
// fn should be a functionfuncPatch(fninterface{}, replacerinterface{}) func()
It should be compatible with the generic version.
As for the mock by name version, also add corresponding PatchByName and PatchMethodByName, but no generic param can be specified. And it is the user's responsibility to ensure the function signature matches.
NOTE: this Patch is not always feasible if some type in the function signature are not exported. In these case, just use the Mock API as before.
The text was updated successfully, but these errors were encountered:
Currently the
mock.Mock(fn,interceptor)
API provides a general way to setup mock.When testing a logic with many external dependencies, the mock setup ends with a lot of
results.GetFieldIndex(0).Set(...)
call, as below:Thus, we propose a new API based on generic:
The above test can be write as following with better type safety:
As for go1.17 and below, the function can just be:
It should be compatible with the generic version.
As for the mock by name version, also add corresponding
PatchByName
andPatchMethodByName
, but no generic param can be specified. And it is the user's responsibility to ensure the function signature matches.NOTE: this
Patch
is not always feasible if some type in the function signature are not exported. In these case, just use theMock
API as before.The text was updated successfully, but these errors were encountered: