All Projects → PauloGoncalvesBH → nirvana-teste-de-contrato

PauloGoncalvesBH / nirvana-teste-de-contrato

Licence: GPL-3.0 license
Example of how to implement nirvana of contract testing with Pact following all the practices described in https://docs.pact.io/pact_nirvana

Programming Languages

javascript
184084 projects - #8 most used programming language
Makefile
30231 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to nirvana-teste-de-contrato

README
Developer Relations @ Pact - Your map to the Pact landscape for all-comers (maintainers, contributors, users, newbies)
Stars: ✭ 35 (-50.7%)
Mutual labels:  pact, pactflow
terraform-provider-pact
Terraform provider for Pact Broker (and Pactflow)
Stars: ✭ 21 (-70.42%)
Mutual labels:  pact, pactflow
MQBench Quantize
QAT(quantize aware training) for classification with MQBench
Stars: ✭ 29 (-59.15%)
Mutual labels:  pact
pact-example
Example project to demonstrate Contract Testing via Pact.
Stars: ✭ 58 (-18.31%)
Mutual labels:  pact
jest-pact
A Pact adaptor for to allow you to easily run tests with Jest
Stars: ✭ 58 (-18.31%)
Mutual labels:  pact
go-microservices-and-krakend-api-gateway
This is a shopping basket workshop that shows how to use KrakenD API Gateway.
Stars: ✭ 44 (-38.03%)
Mutual labels:  pact
pact-workshop-dotnet-core-v1
A workshop for Pact using .NET Core
Stars: ✭ 66 (-7.04%)
Mutual labels:  pact
rust-wildbow-scraper
Automatically scrapes wildbow's web serials and compiles them into ebooks
Stars: ✭ 64 (-9.86%)
Mutual labels:  pact
awesome-contract-testing
Awesome resources for Consumer-Driven Contract Testing
Stars: ✭ 54 (-23.94%)
Mutual labels:  pact
sample-testing-microservices
sample applications with implementation of unit, component, contract and integrarion tests using pact, gatling, spring boot test and hoverfly
Stars: ✭ 22 (-69.01%)
Mutual labels:  pact
testing-microservices-introduction
Learn some of the high level microservices testing cases with hands on examples.
Stars: ✭ 27 (-61.97%)
Mutual labels:  pact
pact-mock service
Provides a mock service for use with Pact
Stars: ✭ 66 (-7.04%)
Mutual labels:  pact
pact-js-core
Core binaries for pact-js, a Contract Testing Framework. NOTE: If you are looking to do Pact contract testing in node, you almost certainly want pact-js, not pact-node.
Stars: ✭ 140 (+97.18%)
Mutual labels:  pact
pact-consumer-swift
A Swift / ObjeciveC DSL for creating pacts.
Stars: ✭ 89 (+25.35%)
Mutual labels:  pact
spring-projects
Some spring sample projects
Stars: ✭ 24 (-66.2%)
Mutual labels:  pact
ContractTestingBoilerplate
Contract Testing Boilerplate for the microservices developed using Spring Boot and Kafka in a maven multi-module project.
Stars: ✭ 36 (-49.3%)
Mutual labels:  pact
pmpact
A command line tool to convert Pact files to Postman collections.
Stars: ✭ 15 (-78.87%)
Mutual labels:  pact

Contract test example - Pact Nirvana

This repository exemplifies the best implementations of contract testing, reaching 'nirvana' and having control via pipeline and pact-broker in a completely reliable way, providing security to go ahead with deploy.

Give the repository a star , it encourages me to create advanced software quality content 100% free

Would you like to learn contract test from 0 to advanced? I provide practical training, just contact me via Linkedin or by email [email protected] and I'll send you the proposal with all the grid and important details.

Contract test basis

To get the most out of the repository, see the following materials, which you need to learn about contract testing concepts:

  1. Introduction - Pact documentation
  2. The steps for reaching Pact Nirvana - Pact documentation
  3. [Portuguese] AT Talks: Contract test with Pact - Paulo Gonçalves
  4. [Portuguese] Contract tests with PACT #1 Concepts - Vinícius Ribeiro

About the repository

The purpose of this material is to demonstrate how the implementation of pipeline and contract testing of provider and consumer applications should be in a way that follows what is considered the Pact Nirvana.

The diagram below is the representation of the Pact Nirvana that was implemented in this repository.

Diagram - Contract Test 'Nirvana'

The pact-cli informed in the diagram refers to Pact Broker Client commands.


Applications

The applications used are divided into 2 directories, each with its source files (/src), tests, dockerfile, package.json, etc., as well as each application has its pipeline implemented in .github/workflows.

Provider - clientsService

The provider is the application that provides an API to be consumed by another service. It's in provider-clients-service.

The provider pipeline runs only when there is a change outside the consumer-frontend (consumer) directory.

Consumer - Frontend

The consumer is the application that consumes another API. It can also be a provider. It's in consumer-frontend.

The consumer pipeline runs only when there is a change outside the provider-clients-service (provider) directory.

Execution

Prerequisites

Consumer contract test

make consumer-test-contract

After execution, the contract is generated in consumer-frontend/pacts and log.

As shown in the diagram, publishing the generated pact in Pactflow is done using the publish command from pactfoundation/pact-cli and only in CI, as can be seen in the consumer-ci pipeline.

Provider contract test

make provider-test-contract

To be able to run the provider test, change the docker-compose file as shown in the example below to use the Pactflow read token and allow you to download the contracts published by the consumer.

    environment:
-     - PACT_BROKER_TOKEN
+     - PACT_BROKER_TOKEN=7L0Ijmqyh7LOMk5DyqteLQ
      - PACT_URL

Publishing the execution result is done only via CI and with a writing token. (publishVerificationResult: process.env.CI == 'true')

Webhooks

Webhook that trigger test contract on Provider

When the consumer publishes a new contract, it is necessary to ensure that the provider has performed on top of this contract.

For this to happen, a webhook is used in Pactflow which, when identifying that a contract with changed content or a new branch has been published, triggers the provider's pipeline by passing the URL of this contract.

The pipeline called via webhook is provider-ci-triggered-by-webhook.yml.

The configuration of can-i-deploy in the consumer pipeline allows it to wait for the contract test to be executed by the provider and the publication of the result to know whether or not it is possible to proceed with the new contract.

Trigger webhook configuration print:

Trigger webhook configuration print

Webhook to publish result

It is important that teams have visibility into the integration between applications, and the way found for this in contract testing is to publish the result of the contract test performed on the provider side in the commit status in the consumer repository.

Every time the contract test is executed on the provider side, regardless of the status of this test, the result of the integration between the applications will be published in the consumer repository with a link to the pactflow.

You will need to create 1 webhook for each consumer

Pact status print on Consumer commit

The status on commit shows which providers have verified the published consumer and which branch have been executed.

In the example in the image, the consumer is successfully integrating with the client-service provider that is deployed to production and in the main branch.

Clicking on details will open the Pactflow page containing the contract published in the commit and all the execution details.

Pact status print on Consumer commit

Output status webhook configuration print on commit:

Output status webhook configuration print on commit


LICENSE GNU General Public License v3.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].