LukeMathWalker / LukeMathWalker/wiremock-rs

Report diff between expected and actual request body sent to a mock

Open
#95 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Rust
Stars
799
Forks
91
PR merge metrics
No merged PRs in 30d

Description

It would be nice to be able to fail a test with a clear diff between the expected and actual request body sent to a mock.

Use case: I'm mocking a third-party XML-based API and want to verify that all requests to it contain the expected data. My mocks currently have a MethodExactMatcher, PathExactMatcher and BodyExactMatcher so they only respond when the exact expected API call is done. For example:

Mock::given(method(Post))
        .and(path(request_path))
        .and(body_string(expected_request_body))
        .respond_with(response_template)
        .mount(mock_server)
        .await;

The drawback of this approach is that when the actual request body contains a small error - the most common place for mistakes - a test fails with a 404 Not Found response because the BodyExactMatcher returns false. Those failures are a bit cumbersome to debug, having to enable debug logging so my code logs sent messages and rerun the test. It would be much nicer when a test failed with a clear diff between the expected and actual request body.

Is there a way to create such behavior with the current wiremock APIs? As far as I can see a custom matcher cannot report errors, and there's no way to add custom expectations either.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing BodyExactMatcher, MethodExactMatcher, and the mock failure path described in the issue, then check how custom matchers and expectations are exposed by the current wiremock APIs. Done means a mismatched request body produces a clear expected-versus-actual diff during test failure without requiring debug logging.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.