in request/response formats, query params and the functionality • Different users using different versions of the same service • Unit-tests ? End-to-end tests ?
services ▪ Which endpoints I use ▪ How do I use ▪ What do I expect in return • each provider verifies contracts provided by all consumers part of its deployment process Consumer Driven Contracts
Provides a mock service ◦ Provides DSL to write contract tests • For provider ◦ Ability to play back tests and verification • Has support in many languages - python, ruby, java, JS, go, node, andriod and more Pact
backend • auto-generate “pact file” • JSON file • contains request-response pairs • share them with provider • provider verifies all pact files during its deployment process Backend app Mobile app Web app Expectations Expectations
pact import Consumer, Provider pact = Consumer('web_app').has_pact_with(Provider('backend_app')) pact.start_service() # starts Pact mock service will be localhost:1234 atexit.register(pact.stop_service) def test_consumer(): name = 'PyCon' expected = 'Hello {}'.format(name) pact.given( 'a name' ).upon_receiving( 'a request to provider with that name' ).with_request( 'get', '/{}'.format(name) ).will_respond_with(200, body=expected) with pact: result = get_greeting(name) assert result.status_code == 200 assert result.text == expected
at web_app-backend_app.json Verifying a pact between web_app and backend_app Given a name a request to with that name with GET /PyCon returns a response which has status code 200 has a matching body 1 interaction, 0 failures