Crate pact_mock_server
source ·Expand description
The pact_mock_server
crate provides the in-process mock server for mocking HTTP requests
and generating responses based on a pact file. It implements the
V3 Pact specification
and V4 Pact specification.
The exported functions using C bindings for controlling the mock server now live in the pact_mock_server_ffi
crate.
§Crate features
All features are enabled by default
datetime
: Enables support of date and time expressions and generators.xml
: Enables support for parsing XML documents.plugins
: Enables support for using plugins.multipart
: Enables support for MIME multipart bodies.tls
: Enables support for mock servers using TLS. This will add the following dependencies: hyper-rustls, rustls, rustls-pemfile, tokio-rustls.
Modules§
- The matching module defines how a request is matched against a list of potential interactions.
- This module defines the external interface for controlling one particular instance of a mock server.
- This module defines a manager for holding multiple instances of mock servers.
- TLS support structs
Structs§
- A global thread-safe, “init-on-demand” reference to a server manager. When the server manager is initialized, it starts a separate thread on which to serve requests.
Enums§
- Mock server errors
- Write Pact File Errors
Functions§
- Sets up all the core catalogue entries for mock servers
- Creates a mock server. Requires the pact JSON as a string as well as the port for the mock server to run on. A value of 0 for the port will result in a port being allocated by the operating system. The port of the mock server is returned.
- Creates a TLS mock server. Requires the pact JSON as a string as well as the port for the mock server to run on. A value of 0 for the port will result in a port being allocated by the operating system. The port of the mock server is returned.
- Find a mock server by port number and and map it using supplied function if found. Returns the result of the function call wrapped in a Some. Returns a None if the mock server was not found.
- Function to check if a mock server has matched all its requests. The port number is passed in, and if all requests have been matched, true is returned. False is returned if there is no mock server on the given port, or if any request has not been successfully matched.
- Gets all the mismatches from a mock server in JSON format. The port number of the mock server is passed in, and the results are returned in JSON format as a String.
- Shuts down the mock server with the provided port. Returns a boolean value to indicate if the mock server was successfully shut down.
- Shuts down the mock server with the provided ID. Returns a boolean value to indicate if the mock server was successfully shut down.
- Starts a mock server with the given ID, pact and port number. The ID needs to be unique. A port number of 0 will result in an auto-allocated port by the operating system. Returns the port that the mock server is running on wrapped in a
Result
. - Starts a mock server for the provided transport. The ID needs to be unique. A port number of 0 will result in an auto-allocated port by the operating system. Returns the port that the mock server is running on wrapped in a
Result
. - Starts a mock server with the given ID, pact and port number. The ID needs to be unique. A port number of 0 will result in an auto-allocated port by the operating system. Returns the port that the mock server is running on wrapped in a
Result
. - Starts a TLS mock server with the given ID, pact and port number. The ID needs to be unique. A port number of 0 will result in an auto-allocated port by the operating system. Returns the port that the mock server is running on wrapped in a
Result
. - Starts a TLS mock server with the given ID, pact and port number. The ID needs to be unique. A port number of 0 will result in an auto-allocated port by the operating system. Returns the port that the mock server is running on wrapped in a
Result
. - Trigger a mock server to write out its pact file. This function should be called if all the consumer tests have passed. The directory to write the file to is passed as the second parameter. If
None
is passed in, the current working directory is used. If overwrite is true, the file will be overwritten with the contents of the current pact. Otherwise it will be merged with any existing pact file.