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

Fail tests on unexpected call #93

Open
sazzer opened this issue May 16, 2022 · 2 comments
Open

Fail tests on unexpected call #93

sazzer opened this issue May 16, 2022 · 2 comments

Comments

@sazzer
Copy link

sazzer commented May 16, 2022

Right now, if a MockServer receives an unexpected call then this gets logged and an HTTP 404 is returned to the client.

It would be useful if there was some way to have the server instead fail tests if it receives an unexpected request. That would not only be more obvious in outputs - especially if the client is expecting a 404 from the server and gets it for the wrong reason - but it also means that, if using WireMock to emulate a real remote service, unexpected API calls to it will be caught quickly.

Cheers

@sazzer
Copy link
Author

sazzer commented May 16, 2022

I can see at least four ways this could be achieved:

  1. Support for a handler that can handle any request but at a lower priority, so that it comes after all others
  2. Some way to indicate in MountedMockSet that unexpected calls should panic instead of returning a 404
  3. Some (sync) way to return at least the count of calls that hit the auto-404 handler in MountedMockSet
  4. Actually have MountedMockSet.verify_all() panic if it ever encountered any unexpected calls

I've no idea which of those would be preferable though.

@sunjay
Copy link

sunjay commented Apr 25, 2024

I've been using approach 1:

        Mock::given(any())
            .respond_with(|req: &_| panic!("Request did not match any expected requests: {req:#?}"))
            .with_priority(u8::MAX)
            .mount(&server)
            .await;

The produced error isn't great, but you can make do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants