Skip to content

A simple example of how to do Consumer-driven Contract Testing using Pact, a consumer written in Rust and a provider written in Python.

License

Notifications You must be signed in to change notification settings

Nefendi/pact-cdc-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pact-cdc-example

This small project shows a relatively simple example of Consumer-driven Contract Testing (CDC) in action.

The chosen framework for CDC is Pact and you can read more about it here.

Consumer side

The consumer side has been written in Rust using the pact_consumer crate and it generates a short contract for GET and POST requests regarding users instances. To run it, simply do:

cd consumer
cargo test

This should download all dependencies, run the integration tests and generate a contract in the pact_contracts directory (the contract is already present in the repository).

Provider side

The provider side has been written in Python using the pact-python and pactman packages. The former package is an official one from the Pact team (which currently supports only the second version of the Pact specification). The latter, is written entirely in Python (pact-python internally runs a server written in Ruby), supports Pact specifications 1.1, 2 and 3, and is now in maintenance phase. To run the provider's contract-verification tests, do (after installing all packages and activating a virtual environment with poetry install && poetry shell):

cd provider
pytest

By default, this will run only the test written using pact-python. To verify the contracts with pactman, go to src/tests/test_verify_pact_contracts.py, comment out the test_verify_pact_contracts_with_pact_python test and uncomment the one below. Then, you can run the tests using the pytest_pactman.sh script (pactman requires to pass a flag with the location of contracts or a URL to a Pact broker).

NOTE: You may see some warnings when running the tests with pact-python. They occur because the pacts generated by the Rust consumer use the third version of Pact specification and pact-python does not yet support it.

I encourage you to make all sorts of changes in both applications to figure out how Pact works. Have fun!

About

A simple example of how to do Consumer-driven Contract Testing using Pact, a consumer written in Rust and a provider written in Python.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published