Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Stenographer logging and playback #132

Merged
merged 5 commits into from
Jul 5, 2014
Merged

Stenographer logging and playback #132

merged 5 commits into from
Jul 5, 2014

Conversation

maxlinc
Copy link
Collaborator

@maxlinc maxlinc commented Jul 3, 2014

Details from the WIP README for upcoming v0.4.0

The Stenographer

The stenographer keeps a short-hand record of everything that happens in the courtroom. These logs can be used for troubleshooting, creating reports, or re-enacting the courtroom activities at a later date (and with different actors.

The stenographer's logs are similar to HTTP access logs in this respect, but in a format that's more compact and suited to Pacto. A typical HTTP access log might look like this:

#Fields: date time c-ip cs-username s-ip s-port cs-method cs-uri-stem cs-uri-query sc-status cs(User-Agent)
2014-07-01 17:42:15 127.0.0.1 - 127.0.0.1 80 PUT /store/album/123/cover_art - 201 curl/7.30.0
2014-07-01 17:42:18 127.0.0.1 - 127.0.0.1 80 GET /store/album/123/cover_art size=small 200 curl/7.30.0

If Pacto has the following services registered:
routes.png

Then it can match those requests to request and generate a stenographer log that looks like this:

request 'Upload Album Art', values: {album_id: '123'}, response: {status: 201} # no contract violations
request 'Download Album Art', values: {album_id: '123', size: 'small'}, response: {status: 200} # no contract violations

This log file is designed so Pacto it can be used by Pacto to simulate the requests:

Pacto.simulate_consumer :my_client do
  request 'Upload Album Art', values: {album_id: '123'}, response: {status: 201} # no contract violations
  request 'Download Album Art', values: {album_id: '123', size: 'small'}, response: {status: 200} # no contract violations
end

Since Pacto has added a layer of abstraction you can experiment with changes to the contracts (including routing) without needing to re-record the interactions with the stenographer. For example Pacto will adjust if you change the route from:
original_put.png
to
new_put.png

Conflicts:
	lib/pacto/core/configuration.rb
	lib/pacto/core/validation_registry.rb
	spec/unit/pacto/validation_registry_spec.rb
@maxlinc
Copy link
Collaborator Author

maxlinc commented Jul 3, 2014

See also samples/stenographer.rb for some stuff that's not currently in the README. In particular, you can playback a stenographer log file without copying pasting:

Pacto.simulate_consumer :my_consumer do
  playback 'pacto_stenographer.log'
end

In the future it may make sense to have something like rake validate which takes a stenographer log and replays each request (w/ variations for different values) rather than just one request per contract.
That'd let a consumer (e.g. in java) launch a pacto server and point their test suite at it (w/ pacto either stubbed or hitting the live service). They could then hand the contracts and stenographer log over the the provider, who could use just pacto to replay the requests w/out the dependency on the consumer (java).

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling fe8548b on stenographer into * on master*.

maxlinc added a commit that referenced this pull request Jul 5, 2014
Stenographer logging and playback
@maxlinc maxlinc merged commit b061db5 into master Jul 5, 2014
@maxlinc maxlinc deleted the stenographer branch July 5, 2014 23:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants