Support for function mocks in v3 #1091
mattdowdell
started this conversation in
General
Replies: 1 comment
-
|
To be honest, it was causing a maintenance headache for me and I found it to not provide enough value for the trouble that it was causing. It's not technically complicated or anything, but during the v3 port, I just decided not to include the logic for it instead of putting effort to port it over. It was more of just an intentional omission rather than an explicit deletion. I gauge community interest through interactions with issues/discussions so anyone who wants this added back should react to the OP. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I was struggling to find the rationale for why support for function mocks were removed in v3, so if nothing else I hope this might help others with a similar question.
Previous discussions:
I can totally see that function mocks aren't always useful. Most of the times I end up with such mocks, they go unused. But there are a couple of cases they have been useful, namely when writing interceptors for gRPC and ConnectRPC.
For example, consider the type of grpc.UnaryClientInterceptor:
If I want to write my own interceptor, I must create a function of method with this type. When I come to test my interceptor, I will pass in appropriate values for most arguments, but I want to also check my interceptor does or doesn't call the invoker. Until now, I would reach for
mockeryto generate a mock for grpc.UnaryInvoker which is defined as:Typically, I want to achieve the following with this:
For ConnectRPC, the desire is the same, but I would implement connect.Interceptor and generate a mock for connect.UnaryFunc.
What I found particularly useful was:
testing.T.Cleanupfunction added by mockery to check whether the mock was called.RunAndReturngenerated method to perform in-depth checks/assertions on inputs to UnaryInvoker/UnaryFunc.Obviously, I can replicate what's been removed and the function signatures don't really ever change, so there's little maintenance burden. But nonetheless, I found function mocks reduced the burden of writing such code, as well as keeping tests mostly consistent for interfaces and functions the test didn't need to be super concerned with the implementation of.
Is there a possibility of revisiting the decision to remove function mocks?
Beta Was this translation helpful? Give feedback.
All reactions