LukeMathWalker / wiremock-rs

HTTP mocking to test Rust applications.
Apache License 2.0
617 stars 70 forks source link

Store received requests #56

Closed tl-alex-butler closed 3 years ago

tl-alex-butler commented 3 years ago

Currently, as far as I can see, all verification is done implicitly by matchers.

However, when testing against mock APIs I tend to prefer setting up very simple mock server matcher logic with manually verifying the received requests afterwards.

This approach can be nicer in some cases as:

Proposal

I'd like to add some sort of API to retrieve received requests from a mock server.

Then scenarios could go something like:

Mock::given(method("GET"))
  .and(path("/foo"))
  .respond_with(ResponseTemplate::new(200).set_body_json(...))
  // ...

run_scenario();

let received_requests = // get the received requests to the mock server `GET /foo` somehow
verify_scenario_requests(received_requests);

Other wiremock-ish libs have this sort of thing, e.g. c# one has .FindLogEntries(matcher). We could make all mock-server automatically record requests, or perhaps make it opt in only.

LukeMathWalker commented 3 years ago

Sounds good to me - having some form of recording functionality was part of the plan anyway to support a "record & replay"/discovery mode. It could also improve error messages massively (e.g. "XYZ was not verified. Here is the list of requests received by the mock server"). I'll spec it out a bit and then come up with a PR!