google / martian

Martian is a library for building custom HTTP/S proxies
Apache License 2.0
2.01k stars 248 forks source link

HTTP/S reponse record and replay #75

Open bramhaghosh opened 8 years ago

bramhaghosh commented 8 years ago

Provide support for HTTP/S response record and replay

Users have asked for the capability to record responses from external services, and then to use those responses as a mechanism to stub out the external service during the execution of a test run.

Proposed Record Mode Workflow

  1. Put Martian into RECORD mode
  2. Instruct Martian to record responses to requests that match a provided keyGen() function.
  3. Provide Martian with the path to the db in which to save responses (bolt?).
  4. As requests that match the provided keyGen() come across, Martian captures the response that comes back from the HTTP roundtrip.
  5. For each response for request that matches the keyGen(), Martian adds a header with a known name (X-Martian-Key) where the value is a string representation of the output of keyGen().
  6. While in RECORD mode, any response modifiers will be applied before capture, maybe. Depends on where on the stack the record/replay modifier lives.
  7. Martian holds the responses in memory, and when Martian leaves RECORD mode, the responses are written to the filesystem to the provided path and filename.

    Proposed Replay Mode Workflow

  8. Put Martian into REPLAY mode and tell it where the response cache db and the keyGen() used in RECORD mode
  9. Martian parses the response cache db and holds it in memory
  10. As requests that match the provided keyGen() come across, Martian grabs any matching response from the cache db, deletes the X-Martian-Key header, and returns the cached response.
  11. Martian applies any other modifiers on the stack - this is where you'd want to put modifiers that remove "dynamic" headers (datetime, etc.)
  12. Martian returns the modified cached response.
bootstraponline commented 7 years ago

Is this still planned? I think it'd be great for testing.

bramhaghosh commented 7 years ago

Yes - it's under active development.

Keep an eye out for it this quarter.

On Thu, Jan 19, 2017 at 10:19 AM bootstraponline notifications@github.com wrote:

Is this still planned? I think it'd be great for testing.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/google/martian/issues/75#issuecomment-273855099, or mute the thread https://github.com/notifications/unsubscribe-auth/AADI-Uz9eRpLjpAmFBCTNEWdB0lJVK6hks5rT6kegaJpZM4HjVnu .

bootstraponline commented 7 years ago

Awesome! Thanks for the info.

bootstraponline commented 7 years ago

Is there an updated ETA?

hueich commented 7 years ago

How should the keyGen() function be passed in? In the JSON config? Or in another modifier before it?

hueich commented 7 years ago

An initial implementation is being worked on in the "caching" branch, for those interested.

bootstraponline commented 7 years ago

It'd be helpful to demo a simple use case of record/playback for Java using okhttp. If this can be used as a wiremock alternative for Android testing, that'd be excellent.