git clone https://github.com/skyrex-mark/Pact-Tutorial-for-Beginner.git
- Install ruby 2.2.0 or later and bundler >= 1.12.0
- Windows users: get a Rails/Ruby installer from RailsInstaller and run it
- unix users
sudo apt install ruby-full
- oepn a new terminal
- Run
git clone https://github.com/pact-foundation/pact_broker.git && cd pact_broker/exampleorcd pact_broker/example - Run
bundle install - Run
bundle exec rackup -p 8080(this will use a Sqlite database. If you want to try it out with a Postgres database, see the README in the example directory.) - Open http://localhost:8080 and you should see a list containing the pact between the Zoo App and the Animal Service
- Click the name of either a provider or consumer
- Click on the arrow to see the generated HTML documentation
- Click on either service to see an autogenerated network diagram
- Click on the HAL Browser link to have a poke around the API
- Click on the book icon under "docs" to view documentation related to a given relation
- open a new terminal
cdto client directory- run
npm installoryarn install - run
npm run testoryarn test, if the test fails , try to runmocha -t 50000 consumer.spec.jsinstead - a pact file will be genreated in the
pactsfolder - run
npm run publishoryarn publish, the pact file.will be published to the local pact broker
- open a new terminal
cd api-service- run
npm installoryarn install. - run
npm startoryarn startto spin up .a local api service - open a new terminal
cdto api-service directory- run
npm run testoryarn testto retrieve the pact from the local broker , verify the pact with local service and send the verification result back to the pact broker
-
Install Docker from here https://www.docker.com/community-edition
-
open a new terminal
-
git clone https://github.com/DiUS/pact_broker-docker.git -
cd pact_broker-docker -
run
docker-compose up -
Wait for the pact broker to go online( 2-5 min)
-
navigate to
http://localhostto see the pact brokerClient:
- Go to the
clientdirectory - Open
publish.js - Change
pactBroker: 'http://localhost:8080'topactBroker: 'http://localhost'
Provider:
- Go to the
api-servicedirectory - Open
provider.spec.js - Change
pactUrls: [ 'http://localhost:8080/pacts/provider/sender/consumer/receiver/latest' ]topactUrls: [ 'http://localhost/pacts/provider/sender/consumer/receiver/latest
- Go to the
@JiahuaZhang for helping me to review this tutorial.