This section describes strategies you can use to test a consumer or provider where a Pact client language doesn't exist.
You will need to build your own DSL to capture the consumer interactions and serialise it into a pact file.
There are two options:
- Using an HTTP interface (simplest)
- Integrating to the native pact libraries via a C interface
The HTTP interface is the easiest to do, albeit it does not have support for message pact, XML and later specification versions. The C interface is more feature complete, but is a little more complicated to integrate.
We'll be using the
pact-mock-service binary, which can be obtained by downloading the Pact CLI tools.
You interact with the tool via HTTP calls and passing a customer
Because of the HTTP interaction, you can very quickly create a wrapper interface to generate pact files and ensure your consumer is compliant.
Here is an example bash script, that shows how to interact with the mock service to produce a contract: https://github.com/pact-foundation/pact-mock_service/blob/master/script/example.sh.
We have exposed a fully functional C interface that can be integrated into most modern languages, OS and architectures. Follow the documentation there for further guidance.
Providers written in languages that don't have native Pact support, you can still verify that they satisfy their Pacts, using the generic Pact Provider CLI Verification tool.
This setup simplifies Pact Provider verification process in any language.
- Publish consumer Pacts to the Pact broker (or create local ones)
- Create an API
- Start your API
- Run the Pact Provider Verifier, configuring it to discover the pacts and verify the locally running provider
- Stop your API
The verifier will then replay all of the Pact files against your running API, and will fail (
exit 1) if they are not satisfied.
There is no testing DSL available so you will need to be sensitive to process exit codes when running this in a CI/CD pipeline.