LukeMathWalker/wiremock-rs

body_json() not working as expected

Closed this issue · 2 comments

I have a struct that I am serializing as JSON and POSTing to a url. When I try and mock the request and use the json! macro to deserialize it does not match the request. Is should match I think?

struct -> struct (OK)
json! -> json! (OK)
struct -> json! (NOT WORKING)
json! -> struct (NOT WORKING)

I've put together a quick repo to replicate the problem
https://github.com/longfellowone/wiremockerr/blob/main/src/main.rs

Edit: Also is there any way you can print the incoming json when trying to troubleshoot so it can be compared?

The current JSON matcher is quite brittle, because it looks for an exact comparison - down to the bytes.
A better implementation would compare the parsed serde_json::Value, as a start.

To see the incoming request - it should be included automatically in the panic message - e.g.

thread 'post' panicked at 'Verifications failed:
- /first.
        Expected range of matching incoming requests: == 1
        Number of matched incoming requests: 0

Received requests:
- Request #1
        POST http://localhost/second
user-agent: curl/7.80.0-DEV isahc/0.9.14
host: 127.0.0.1:40463
accept: */*
accept-encoding: deflate,gzip
content-length: 14
content-type: application/json
{"hi":"hello"}
', src/mock_server/exposed_server.rs:363:17