Pact: Consumer-Driven Contract Testing in Go

661bb4dee881617e676c4d954ce97a70?s=47 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.

661bb4dee881617e676c4d954ce97a70?s=128

Konrad Reiche

November 10, 2016
Tweet

Transcript

  1. Pact Consumer-Driven Contract Testing in Go

  2. Hi, I’m Konrad

  3. None
  4. None
  5. 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
  6. 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
  7. 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
  8. 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
  9. Pact to the Rescue

  10. 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
  11. 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
  12. Bouncer API • •

  13. Bouncer Schaffner Box Office Persist ticket Validate ticket Consumer Consumer

    Producer
  14. None
  15. None
  16. Bouncer Schaffner Box Office Persist ticket Validate ticket Consumer v1

    Consumer v1 Producer v1
  17. Bouncer Schaffner Box Office Consumer v1 Consumer v1 Producer v2

    JSON JSON
  18. Bouncer Schaffner Box Office Consumer v2 Consumer v1 Producer v2

    JSON JSON
  19. Pact for Go Pact Foundation Documentation https://pact.io Pact for Go

    https://github.com/pact-foundation/pact-go #pact https://gophers.slack.com
  20. 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
  21. Thanks We are hiring http://jobs.tape.tv Ping me konrad.reiche@gmail.com Follow me

    @konradreiche