Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Pact: Consumer-Driven Contract Testing in Go

Konrad Reiche
November 10, 2016

Pact: Consumer-Driven Contract Testing in Go

Pact is a tool to implement consumer-driven contract testing. Consumer-Driven Contracts is a technique or an attitude to define expectation of one service (consumer) on another service (producer) and test those in isolation without the need to deploy the whole stack or do costly end-to-end tests. Breaking changes can then be efficiently communicated to the team in charge.

Konrad Reiche

November 10, 2016
Tweet

More Decks by Konrad Reiche

Other Decks in Technology

Transcript

  1. Bouncer Schaffner Jet Streams Video Feed Box Office Persist segments

    Persist ticket Android App iOS App Web Player Play livestream Tickets Purchase tickets Validate ticket Deliver playlist
  2. Bouncer Schaffner Jet Streams Video Feed Box Office Persist segments

    Persist ticket Android App iOS App Web Player Play livestream Tickets Purchase tickets Validate ticket Deliver playlist
  3. What’s wrong with testing? • Too few tests? You’re doing

    it wrong. • Too many tests? You’re doing it wrong. End-to-End Tests • Need to deploy multiple services together in a separate environment • More scope, will take longer to execute • Deploy which version of each service? • Harder to diagnose errors • Multiple end-to-end tests result in redundant test coverage
  4. Test Ownership in End-to-End Tests • Who writes the end-to-end

    tests? • Shared ownership • Metaversion: version number for the whole system • It becomes okay to change and deploy multiple services at once • Introduces coupling into a microservice architecture • Defeating the whole purpose of using microservices in the first place “Now you have 2.1.0 problems.” — Brandon Byar
  5. Consumer-Driven Contract (CDC) • Consumer and Producer are services •

    Consumer has expectations on a Producer • The expectations are captured in form of a contract • Expectations can be run in isolation of the consumer services • Producer tests consumer provided contract on itself • If something breaks it becomes obvious which consumer is affected • Ideally these contracts are run as part of the CI
  6. Pact • Started out as a tool written in Ruby

    • Now a family of frameworks to implement Consumer-Driven Contract testing • Pact is a tool to verify the contracts are satisfied Consumer Expectations using Pact DSL Pact Mock Server Generate Pact Contract (JSON) Pact Broker Producer Pact helper Producer service
  7. Pact for Go Pact Foundation Documentation https://pact.io Pact for Go

    https://github.com/pact-foundation/pact-go #pact https://gophers.slack.com
  8. It’s About Conversation • In agile stories are seen as

    a placeholder for a conversation • For CDC the same argument applies • Codification of a set of discussions about the service API • If they break: it becomes a conversation • Value in CDC: semi-automates this conversation • CDC is an investment and comes at a cost • Takes a lot of time to set this up and get everyone used to it