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. Pact
    Consumer-Driven Contract
    Testing in Go

    View Slide

  2. Hi, I’m
    Konrad

    View Slide

  3. View Slide

  4. View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  9. Pact to the Rescue

    View Slide

  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

    View Slide

  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

    View Slide

  12. Bouncer API


    View Slide

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

    View Slide

  14. View Slide

  15. View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

  21. Thanks
    We are hiring http://jobs.tape.tv
    Ping me [email protected]
    Follow me @konradreiche

    View Slide