hi all, is there an easy way to have the mock serv...
# pact-jvm
u
hi all, is there an easy way to have the mock server ignore headers sent by a client? (without rewriting requests)
u
The mock server does ignore headers that are not specified in the interaction.
u
oh, interesting, because I’m debugging a failed test which fails with a
500
+
null
and I thought it’d be the extra headers that the client is sending
what’s the best way to go about debugging this failing test?
m
Are you using JUnit, it should print a report with the mismatch info in it Otherwise, you could enable debug logging through the usual java means (SLF4J I think)?
u
right, that’s what I’ve been trying to do. The mismatch reported by junit5 simply says “unexpected request”, and dumps everything, though there’s no indication as to what was unexpected about the request itself
it’s not my codebase, so I’m struggling to increase log levels via slf4j but that’s a diff issue, I was just hopeful I could add a flag/variable here and there (in the annotations for instance) that’d make my life easier
also slack is not notifying me of these things, apologies for the slow replies and thanks for taking the time to help
m
Argh, sorry to hear. I can’t help too much as it’s literally been 10 years since I’ve had to write any Java (or JVM based stuff).
no worries on the slow replies - there are already too many ways to be “notified” these days!
right, that’s what I’ve been trying to do. The mismatch reported by junit5 simply says “unexpected request”, and dumps everything, though there’s no indication as to what was unexpected about the request itself
hmm. No HTML report written to file anywhere though?
u
none that I can see 😞
y
Hey @Ulises Cervino, I am also not a Pact JVM'er but happy to rubber ducky with you today for a bit if you want
u
hi! Thanks for the offer. Today I can’t, next week I’ll give it another go and I’ll reach out to you then if that’s all right?
y
sure thing, Jo Laing will be gutted she'll miss you as she is on holidays next week.
u
we can do it later too when she’s back
ok, actually, check this out this is what I get when I run a consumer test:
Copy code
ApiException{code=500, endpoint=<http://localhost:63004/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee>, responseHeaders={access-control-allow-origin=[*], content-length=[762], content-type=[application/json], date=[Fri, 12 May 2023 11:32:45 GMT], x-pact-unexpected-request=[1]}, responseBody='{ "error": "Unexpected request : \tmethod: PUT\n\tpath: \/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\n\tquery: {}\n\theaders: {Accept-encoding=[gzip], X-booking-timeout-ms=[5000], Accept=[application\/json], X-booking-request-max-attempts=[1], Connection=[Keep-Alive], Host=[localhost:63004], X-booking-trace-meta=[caller_persona=\"banana\"], X-booking-request-attempt=[1], User-agent=[<http://Booking.com|Booking.com> Internal B.Client v6.52.0], X-booking-topic=[b-basket-platform-basket-service], Content-type=[application\/json], Content-length=[77], Tracestate=[evsystem=caller_persona:\"banana\"]}\n\tmatchers: MatchingRules(rules={})\n\tgenerators: Generators(categories={})\n\tbody: PRESENT({\"creator\":\"FLIGHT\",\"booker\":{\"BUID\":\"11111111-2222-3333-4444-555555555555\"}})" }'}
I understand that this 500 is because I prepped the mock server to receive a particular request, and in my unit test I’m not sending the exact same request
that’s fine (if correct), what I need now is a diff of what I’m missing
is it buried in that message somewhere? (the rest is generic jvm stacktrace)
y
do you get a junit xml report that has more detail? I think the last time I used the kotlin example there stdout wasn't much use, but there was detail in a report, memory fades 😅
u
right, we don’t get that
y
Hmm I noted you had you SLF4J issues the docs state https://docs.pact.io/implementation_guides/jvm/consumer/junit#debugging-pact-failures Might be worth seeing if we can shave the SLF4J yaks
u
right, I just fixed it
🙌 1
the issue is that serialisation was including stuff like
field: null
in how I was setting up the mock
y
ahhh yeah them pesky nulls!
u
which means the mock wanted the field to be there, but the client serialises requests to skip these fields
nod hmm yes
y
nice, yeah in JS you can set keys to undefined and then when you serialise into json they magically disappear
Superb! Job jobbed 🙂 Can go get a covfefe, happy testing @Ulises Cervino
u
right, the thing is that you can set up the mock server manually (very explicit but cumbersome) or do something like
mapper.writeAsString(new RequestThing().withField("blah"))
and use the resulting string for the mock server
enjoy your coffee and thanks for making me look into this again
y
There are some nice little helpers some people have posted in this channel to make this less onerous to write, I haven't captured them but a ctrl+f on this page (plus plenty of 🐏 for chrome ) https://docs.pact.io/slack/pact-jvm.html Or rendered slightly prettier https://www.linen.dev/s/pact-foundation/c/pact-jvm These archive the entirety of slack so helpful resources
👀 1
enjoy your coffee and thanks for making me look into this again
My pleasure! on the again - I'm sure there is something we could add maybe into some troubleshooting notes to help others out in the future
j
Hi, I came across this thread while searching for solutions for the "unexpected request" I'm facing. Could someone please let me know how to enable debug level logging for
<http://au.com|au.com>.dius.pact.consumer.UnfilteredMockProvider
?
u
Pact-JVM uses SLF4J for logging. I would recommend using Logback for logging, unless you are using Spring.
j
@uglyog Thanks for the suggestion! Unfortunately, the project I'm working on is using Log4J 2.
u