One of the features a plugin can provide is a protocol transport implementation. For these, the plugin needs to provide the following features:
The plugin is required to be able to create a mock server for the protocol, given a Pact file. The mock server is required to accept and decode requests or messages, validate what is received against the provided Pact file, and then return an appropriate response based on what is defined in the Pact file.
The plugin is required to be able to verify a provider, given a Pact file. For each interaction in the Pact file, it needs to be able to construct a request/message using the Pact file, and send it to the provider. Finally, it needs to be able to validate the response from the provider using the details in the Pact file.
Content Matcher and Generator
If the protocol uses a non-standard payload format, a content matcher and generator must also be provided. See Content matcher design docs.
Plugin catalogue entries for protocol transports
When a plugin loads, it will receive an
InitPluginRequest and must respond with an
InitPluginResponse with the
catalogue entries for the plugin. See the plugin proto file for details of these messages.
For protocol transports, the entries need to include:
The entry type must be set to
This should be the name of the protocol.
Example interaction from a consumer test
High Level Summary
- Plugin driver is responsible for starting the plugin. The Pact framework communicates instructions for each Test Session to the plugin via the plugin driver and the gRPC interface.
- The Pact framework will maintain the details of the TestSession - including interactions, failures, logs etc.
- The calling test code is now able to configure the Interactions. For each interaction, the configuration for the interaction is passed to the plugin, which returns the configured Pact Interaction data which is then stored by the Pact framework in the Pact file. The plugin is responsible for defining what an Interaction looks like and how it should be passed in for its specific combination of protocol, payload, transport and interaction type.
- During Test Execution:
- The Interactions from step 3 are passed to the plugin to create a mock server. The mock server details are returned (mostly, the port number).
- the calling code communicates directly to the Mock Service provided by the plugin. The mock server is responsible for handling the request, comparing the request against the registered interactions, and returning a suitable response. It must keep track of the interactions that were matched during the test session.
- After each individual Test Execution, the plugin is requested to shut the mock server down and return any mismatches.
- If the Test Session was successful, write_pact() is called which will write out the actual pact file.
- The plugin is shutdown by the Plugin driver.
Consumer Sequence Diagram
Example consumer test
For an example of a simple gRPC consumer test, see JVM gRPC Consumer.
Example interaction for verifying a provider
High Level Summary
- Plugin driver is responsible for starting the plugin. The framework communicates instructions for each Test Session to the plugin via the plugin driver and the gRPC interface.
- Pact framework fetches the pact files (e.g. from the broker), including the pacts for verification details if configured, and stores this information.
- Pact framework detects plugin specific configuration in the Pact file and instructs the plugin driver to load the plugin.
- The user test code starts the Provider Service
- For each Pact interaction, the Pact framework will be responsible for configuring or invoking provider states.
- The Pact framework will maintain the details of the TestSession - including pacts, interaction failures, pending status, logs etc.
- The Pact framework will pass the Pact interaction to the plugin. The plugin will then perform the plugin-specific interaction, communicating with the Provider Service and returning any mismatches to the Pact framework. This process repeats for all interactions in all pacts.
- Pact framework calculates the verification status for the test session, and optionally publishes verification results back to a Broker.
- The Pact client library then conveys the verification status, and the driver terminates all plugin processes.
Provider Sequence Diagram
Example provider test
For an example of a simple gRPC provider test, see JVM gRPC Provider.