lipanski / mockito

HTTP mocking for Rust!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

lewcinho opened this issue · comments

  • Rust version: 1.58.1
  • Mockito version: 0.30.0

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
}

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