improve collaboration and confidence with consumer-driven contracts

Post on 11-Apr-2017

123 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Consumer-driven contractsImproving collaboration and confidence

@PierreVincent

March 21st, 2017

PIPELINE

Pierre VincentTechnical Team Lead at Newsweaver

techblog.newsweaver.com

@PierreVincent

From this... … to this.

LoginService

UserService

APIGET /users/pierre

{ "user": "pierre", "name": "Pierre Vincent", "role": "publisher"}

200 OK

How do we test this?

Running in Prod Tests Pass in Build

Implement changes

Deployed in Prod

User Service

LoginService

!

✓ ✓ ✓ ✓

{ ... "role": "editor"}

{ ... "roles": ["publisher","editor"]}

Running in Prod

✓ ✓

Maybe we should have tested before deploying to production…?

Tested what though?

UsersService

LoginService

IP CheckService

Token Gen

Service

Cert/KeyService

LoginFrontend

We only wanted to

test this bit!

Contract

LoginService

UserService

API

Authentication Team Users Team

[docs.pact.io]

PACT Specification

Verification philosophy: Tolerant Reader

Implementation guidelines

Implementations

LoginService

UserService

API

PactMock

Server

Authentication Team Users Team

PactConsumerUnit Test

Define interaction

Trigger interaction

GeneratePact

PactProvider

Test

SharePact

Replay interaction

Replay & Verify

Play &Record

Consumer

Provider

Provider State

Request

ExpectedResponse

Login Service

User Service

Given that user 'pierre' exists

Method GETPath /users/pierreHeaders

Accept: application/json

Status 200Headers

Content-Type: application/jsonBody

{ "user": "pierre", "name": "Pierre Vincent", "role": "publisher"}

Interaction

UserService

API

1. Set Provider State

2. Send Request

3. Verify Response

Interaction Verification Test

INSERT INTO users [...]

GET /users/pierreAccept: application/json

{ "user": "pierre", ...}

{ "user": "pierre", ...}

?

AuthenticationDev Team

UsersDev Team

CMSDev Team

BillingDev Team

Pact Broker

PACTPACT PACTPACT

PACTPACT

PACTPACT

PACT

PACT

Pact Broker

DependencyGraphs

Living documentation by example

✓ Versioning

✓ Tagging

✓ REST ApiBuild/Deployment Pipeline integration

Provider pipeline

Implement changes Get Pacts from Broker Replay & Verify Interactions

Deploy Service

Build

Deploy to EU

PROD-EU

Get Pacts from Broker Replay & Verify Interactions

Stop deployment of incompatible Provider

Stop introduction of breaking change

PROD-US

PROD-EU

Consumer pipeline

Implement changes

Generate Pacts (Build)

Push Pacts to Broker Tag Pacts

Each Provider verifies Pacts Deploy Service Tag Pacts

Build

Deploy to EU

HEAD

Stop deployment of incompatible

Consumer

HEAD

PROD-EU

Caution: side-effects may include teams collaborating on API design

Provider state setup for each interaction

Don’t limit contracts tohappy paths interactions

Automation withindeployment pipeline isn’t trivial

What’s the catch…?

After 2 years of CDCs...

Increased confidence when coding & deploying

✓Collaborative API design

✓Living API documentation

Pact docs.pact.io, github.com/pact-foundationSpring Cloud Contract (JVM only) https://cloud.spring.io/spring-cloud-contract

Try it out!

“Pact Matrix” (Beth Skurrie) rea.tech/enter-the-pact-matrix-or-how-to-decouple-the-release-cycles-of-your-microservices

Why should you use CDC for microservices integration teststechblog.newsweaver.com/why-should-you-use-consumer-driven-contracts-for-microservices-integration-tests

Sharing CDCs with Pact Brokertechblog.newsweaver.com/sharing-consumer-driven-contracts-with-pact-broker

More reading...

techblog.newsweaver.com

Questions?

@PierreVincent

top related