LukeMathWalker / wiremock-rs

HTTP mocking to test Rust applications.
Apache License 2.0
617 stars 70 forks source link

body_json() not working as expected #79

Closed longfellowone closed 2 years ago

longfellowone commented 2 years ago

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?

LukeMathWalker commented 2 years ago

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.

LukeMathWalker commented 2 years ago

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