Skip to content

Latest commit

 

History

History
76 lines (46 loc) · 3.36 KB

README.md

File metadata and controls

76 lines (46 loc) · 3.36 KB

Pact Mock Service

This codebase provides the mock service used by implementations of Pact. It is packaged as a gem, and as a standalone executable for Mac OSX and Linux (Windows coming soon.)

The mock service provides the following endpoints:

  • DELETE /interactions - clear previously mocked interactions
  • POST /interactions - set up an expected interaction
  • GET /interactions/verification - determine whether the expected interactions have taken place
  • POST /pact - write the pact file

As the Pact mock service can be used as a standalone executable and administered via HTTP, it can be used for testing with any language. All that is required is a library in the native language to create the HTTP calls listed above. Currently there are binding for Ruby and Javascript. If you are interested in creating bindings in a new langauge, and have a chat to one of us on the pact-dev Google group.

Usage

With Ruby on Mac OSX and Linux

$ gem install pact-mock_service
$ pact-mock-service --port 1234

Run pact-mock-service help for command line options.

With Ruby on Windows

Check out the wiki page here.

With SSL

If you need to use the mock service with HTTPS, you can use the built-in SSL mode which relies on a self-signed certificate.

$ pact-mock-service --port 1234 --ssl

Mac OSX and Linux, without Ruby

See the releases page for the latest standalone executables.

Windows, without Ruby

See the releases page for the latest standalone executables.

Stubbing a service based on a previously generated pact file

NOTE: This is not the intended use of the mock server, and its use as a stub is not officialy supported. Please read the following FAQ: Why are the pacts generated and not static?

It is sometimes useful to be able to run a known service as a stub (a non-verified mock) in order to isolate your system under test.

This example assumes your have already created a Pact contract describing the services expected behaviour, and that you have pact mock server installed correctly.

First we need to run the pact mock service

pact-mock-service --port=1234 --pact-specification-version=2.0.0

Now we need to upload our pact file that describes what requests to expect and what responses should be given.

curl -X PUT \
-H "Content-Type: application/json" \
-H "X-Pact-Consumer: ExampleConsumer" \
-H "X-Pact-Provider: ExampleProvider" \
-d @ExampleConsumer-ExampleProvider.json \
http://localhost:1234/interactions

We can now test our mock by curling to it as if it was a normal service. In this example the pact file describes an endpoint called 'helloworld'.

curl http://localhost:1234/helloworld

Contributing

See CONTRIBUTING.md