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
In this example, I'm writing an unit test for the SampleMethod function. I will have a mocked struct that replaces the real kubeClient. The thing is: the real client will populate the myKubernetesObject struct, and subsequent logic depends on the content of that object to be filled (as you can see on the subsequent if condition).
Has Mockery any out of the box solution for this? For example, being able to define hooks that would be called by the Mocking framework, and could be used to manipulate the input objects received by the mocked methods? Something like:
Here, the Mocking framework would invoke my side_effect function declared inline, to mutate the input object, so the SampleMethod can be tested properly.
Maybe I missed something from reading the docs, or maybe this is not supported at all?
Thanks in advance!
The text was updated successfully, but these errors were encountered:
This particular method allows you to define a function that will take as input the arguments of your function, perform some action, and have your mock return the same values as what your RunAndReturn function returns.
Alternatively, you could use testify's Run method directly but this isn't as type safe, so RunAndReturn is the best way to do this.
I admit that the docs are not super clear about this, that's something for me to fix.
Description
I was wondering if it's possible to define functions to be able to manipulate the state of objects that are sent as inputs to the Mock object.
See the example function below:
In this example, I'm writing an unit test for the
SampleMethod
function. I will have a mocked struct that replaces the realkubeClient
. The thing is: the real client will populate themyKubernetesObject
struct, and subsequent logic depends on the content of that object to be filled (as you can see on the subsequent if condition).Has Mockery any out of the box solution for this? For example, being able to define hooks that would be called by the Mocking framework, and could be used to manipulate the input objects received by the mocked methods? Something like:
Here, the Mocking framework would invoke my
side_effect
function declared inline, to mutate the input object, so theSampleMethod
can be tested properly.Maybe I missed something from reading the docs, or maybe this is not supported at all?
Thanks in advance!
The text was updated successfully, but these errors were encountered: