`Or()` and `And()` don't work correctly
Moon1706 opened this issue · 2 comments
Moon1706 commented
Hey! Today I've tried to make Matcher
using Or
:
httpmock.BodyContainsString(`"subject":"incorrect"`).Or(httpmock.BodyContainsString(`"scenario":"incorrect"`))
and figured out that in 100% of cases, the first matcher was working correctly, but the second one, which was called in Or()
function, was ignored. I suppose there is an issue in this line: https://github.com/jarcoal/httpmock/blob/v1/match.go#L246 . Could you check, please?
maxatome commented
Just as a note, do you know tdhttpmock? it allows you to match JSON content very easily, as it seems it is your case here:
httpmock.RegisterMatcherResponder(
http.MethodPost,
"/test",
tdhttpmock.JSONBody(td.Any(
td.SuperJSONOf(`{"subject":"incorrect"}`),
td.SuperJSONOf(`{"scenario":"incorrect"}`),
))
See Any and SuperJSONOf doc.
Or if you don't care the JSON is correct, but using regexp:
tdhttpmock.Body(td.Re(`"(subject|scenario)":"incorrect"`))
See Re doc.