lipanski / mockito

HTTP mocking for Rust!
MIT License
686 stars 59 forks source link

matchbody with PartialJson no match causes serde::json::error::Error - EOFWhileParsingValue #147

Closed lewcinho closed 1 year ago

lewcinho commented 2 years ago

When using mockito's matchbody method to match requests, when a request is received that is not a good match, a serde::json::error::Error is thrown. This makes troubleshooting the test case difficult, as information on which requests the mock did receive are not exposed at any point.

Example:

#[async_std::test]
async fn test_demonstate_mockito_json_error_eof() {
    let client = SomeApiClient::new(&mockito::server_url());

    let mock = mock("POST", "/")
        .match_body(Matcher::PartialJson(json!({
            "someFlag": true,
        })))
        .with_status(200);

        // send_request forwards the body json
    let result = client
        .send_request(json!({
            "someFlag": false,
        }))
        .await
        .expect("Received some unexpected error"); // panic here with EOF error

    mock.assert() // never reached
}
lipanski commented 1 year ago

This might be fixed in https://github.com/lipanski/mockito/releases/tag/0.32.0 - please give it a try