Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mdenburger opened this issue Jun 30, 2022 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@mdenburger
Copy link

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.

@LukeMathWalker
Copy link
Owner

I don't believe this is possible given the current API, but it'd definitely be a significant improvement in ergonomics.
I'll think about a mechanism to make that feasible 🤔

@LukeMathWalker LukeMathWalker added the enhancement New feature or request label Jun 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants