LukeMathWalker / wiremock-rs

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

Record and playback #65

Closed nirvdrum closed 3 years ago

nirvdrum commented 3 years ago

Is record and playback in scope for this project? I'm after something like VCR for Ruby, where real external requests can be made and recorded. Subsequent tests will load up the previously recorded requests and if a request matches exactly, its response will be returned to the client. If no such request can be found (e.g., the client changed something since the last recording), then a 404 will result.

In Ruby, it's achieved by mocking out the client. I realize this project is a bit different. What I'm proposing is the WireMock server would function as a proxy when recording and disallow external connections when in playback mode.

I'm currently looking at ways to achieve this with WireMock. But, if the tool just fundamentally isn't designed for that, it'd be helpful to know. If I can get it working, I'm happy to contribute it back.

LukeMathWalker commented 3 years ago

wiremock-rs currently supports request recording (see https://docs.rs/wiremock/0.5.2/wiremock/struct.MockServerBuilder.html#method.disable_request_recording and https://docs.rs/wiremock/0.5.2/wiremock/struct.MockServer.html#method.received_requests) but it does not support what is commonly referred to as "Record & Playback" because it would require persisting state outside of a test run (using the simplest implementation strategy, you'd also need DNS tricks for a more advanced one).

It is definitely possible to build the functionality using wiremock-rs, but I don't see that landing in the crate itself right now. A project you might be interested into is stubr, which might fulfill your needs (cc @beltram).

beltram commented 3 years ago

Yes that would definitely be a great feature for stubr.
I planned to implement it sometimes anyway. Recording should be pretty straightforward to implement.
@nirvdrum let's discuss this in a new issue in stubr if you want !

nirvdrum commented 3 years ago

Thanks. I'll close this out then. I hadn't come across stubr (or wiremock for that matter) before. I'll have to spend some time with each and decide where to go from there.

nirvdrum commented 3 years ago

In case anyone comes across this issue, there's now a tracking issue for this functionality in stubr.