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 full-size slide

  2. Hi, I’m
    Konrad

    View full-size slide

  3. 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 full-size slide

  4. 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 full-size slide

  5. 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 full-size slide

  6. 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 full-size slide

  7. Pact to the Rescue

    View full-size slide

  8. 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 full-size slide

  9. 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 full-size slide

  10. Bouncer API


    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  15. 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 full-size slide

  16. 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 full-size slide

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

    View full-size slide