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
Obviously the problem affects floats and ints alike. A simple fix seems to be to return Like(0) as default or return Like(0.0) respectively. However I've just discovered the problem and my knowledge of the pact-go codebase is not deep enough to foresee the consequences of this change, so I didn't create PR yet. Could anybody more experienced comment on this?
Steps to reproduce
Use the interaction builder with a response as specified above and observe the generated pact files response body.
The text was updated successfully, but these errors were encountered:
Metamogul
changed the title
Generating Matcher from pact struct tags produces wrong values in contract for numbers with value 0
"example=0" struct tags for numbers lead to wrong example values in contract
Apr 26, 2024
mefellows
added
bug
Indicates an unexpected problem or unintended behavior
triage
This issue is yet to be triaged by a maintainer
labels
May 2, 2024
Yeah I can't see why we need to even check the value is 0 in the int-like cases. In the case of a floating point number, 0.0 when sent over the wire (i.e. as JSON) is implementation dependent and may get sent as 0 - so we defer to a non-zero number there to preserve the floating point.
I'm open to a PR that allows zero though because ultimately, the user can just update the test to a different number should the downscaling occur.
Software versions
[email protected]
Expected behaviour
If I define a struct like
and use it in building an interaction response such as
I'd expect these values to be reflected in the response body in the json pact files like
Actual behaviour
Instead, the example for the float with the specified example value
0
is set to1.1
:This is caused by the following implementation in
matchers/matcher.go:328
:Obviously the problem affects floats and ints alike. A simple fix seems to be to
return Like(0)
as default orreturn Like(0.0)
respectively. However I've just discovered the problem and my knowledge of the pact-go codebase is not deep enough to foresee the consequences of this change, so I didn't create PR yet. Could anybody more experienced comment on this?Steps to reproduce
Use the interaction builder with a response as specified above and observe the generated pact files response body.
The text was updated successfully, but these errors were encountered: