Skip to content

sauldeleon/pact-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pact example

Requirements

Run the pact-broker

  • Go to pact-broker folder

  • Create broker.env and database.env files based on sample files in the same folder. Have in mind that the same values should be applied to both files or the app won't connect with the database

  • In order to use https you have to add your ssl certificate, generate pact_cert.pem and pact_cert.key files and push them into packages/pact-broker/ssl/cert folder. Uncomment the SSL section of Nginx Configuration file and set your desired configuration, lines 16 and 17, with your custom certificate paths. Use the following command to generate the certificates.

    openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout pact_cert.key -out pact_cert.pem
  • Run docker-compose up -d

  • Use your browser to open http://localhost or https://localhost if ssl is configured correctly

Javascript


Javascript set up

  1. Go to javascript folder

  2. Install dependencies with yarn

    cd javascript
    yarn
  3. Run pact tests ⤵️

Running Pact tests

  • In the javascript directory, run yarn pact. It will run the pact tests in each project and will generate the pacts inside each package within the pacts folder. yarn pact:publish will publish the pact results of the consumers. yarn pact:verify will verify all existing published pacts by each respective provider.
  • You can also run manually each pact test or publishing with the following commands:
    • yarn pact:hachebo: hachebo pact testing and generate pacts
    • yarn pact:hachebo:publish: hachebo pact publish results
    • yarn pact:neflis: neflis pact testing and generate pacts
    • yarn pact:neflis:publish: neflis pact publish results
    • yarn pact:tv-shows: tv shows pact testing and generate pacts
    • yarn pact:tv-shows:publish: tv shows pact publish results
    • yarn pact:tv-shows:verify: tv shows verify pacts

Python


Python set up

cd pact-example/python
python3 -m venv venv
source ./venv/bin/activate
pip install .

Start local apps

Start duration-provider

cd duration_provider
uvicorn main:app --reload --port 9000

Start movies-api

cd movies-api
uvicorn main:app --reload --port 9001

Start all servers in background

make servers-start

Shutdown servers

make servers-shutdown

Pacts

Generate movies-api pacts

make movies-api-generate

Publish movies-api pacts

make movies-api-publish

Verify movies-api pacts

make movies-api-verify

Verify duration-provider pacts

make duration-provider-verify

Schemas


Regarding consumer schemas information, check this

About

Pact example with 2 consumers and 2 providers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •