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 our tests, we use mockery, so we can mock the return value of our methods.
If I isolate my HTTP request in a method and return the resty.Response struct, I cannot mock the body value.
In the following example, my GetData() method will call the SendPostRequest() method that is mocked, with mockery I will set the value return from the SendPostRequest(), that will be used afterwards in GetData().
If I try to access the Body value from the response.Body() it will return nill, bacause the method returns the value from the Response struct, which is private.
All the other methods/values available in the Response struct, return the value from the RawResponse (for example the StatusCode or Status), only the value of body comes from a different source.
Why the Body method check for RawResponse value if it will return the value of body instead of Response.Body?
How can I set a custom body value directly in the Response structure instead of the RawResponse? So I can get the value with Body().
The text was updated successfully, but these errors were encountered:
BrunoKrugel
changed the title
Unable to teste Body() due to unexported variable body
Unable to test Body() due to unexported variable body
Oct 4, 2023
In our tests, we use mockery, so we can mock the return value of our methods.
If I isolate my HTTP request in a method and return the
resty.Response
struct, I cannot mock thebody
value.In the following example, my
GetData()
method will call theSendPostRequest()
method that is mocked, with mockery I will set the value return from theSendPostRequest()
, that will be used afterwards inGetData()
.If I try to access the
Body
value from theresponse.Body()
it will return nill, bacause the method returns the value from theResponse
struct, which is private.All the other methods/values available in the Response struct, return the value from the
RawResponse
(for example theStatusCode
orStatus
), only the value ofbody
comes from a different source.Why the Body method check for
RawResponse
value if it will return the value ofbody
instead ofResponse.Body
?How can I set a custom
body
value directly in the Response structure instead of theRawResponse
? So I can get the value withBody()
.The text was updated successfully, but these errors were encountered: