64 releases

0.9.7 Dec 19, 2022
0.9.5 Nov 28, 2022
0.9.1 May 30, 2022
0.8.8 Mar 24, 2022
0.2.0 Jul 13, 2016

#89 in Testing

Download history 79/week @ 2022-10-08 105/week @ 2022-10-15 76/week @ 2022-10-22 160/week @ 2022-10-29 206/week @ 2022-11-05 247/week @ 2022-11-12 273/week @ 2022-11-19 241/week @ 2022-11-26 162/week @ 2022-12-03 660/week @ 2022-12-10 509/week @ 2022-12-17 133/week @ 2022-12-24 90/week @ 2022-12-31 105/week @ 2023-01-07 124/week @ 2023-01-14 199/week @ 2023-01-21

533 downloads per month
Used in 7 crates (6 directly)

MIT license

1.5MB
30K SLoC

Pact Mock Server library

This library implements the in-process mock server for matching HTTP requests and generating responses from a pact file. It implements the V3 Pact specification and V4 Pact specification.

Online rust docs

All the exported functions using C bindings for controlling the mock server are now found in the pact_ffi module.

create_mock_server

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.

mock_server_matched

Simple function that returns a boolean value given the port number of the mock service. This value will be true if all the expectations of the pact that the mock server was created with have been met. It will return false if any request did not match, an un-recognised request was received or an expected request was not received.

mock_server_mismatches

This returns all the mismatches, un-expected requests and missing requests in JSON format, given the port number of the mock server.

shutdown_mock_server

Shuts down the mock server with the provided port. Returns a boolean value to indicate if the mock server was successfully shut down.

write_pact_file

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.

Returns Ok if the pact file was successfully written. Returns an Err if the file can not be written, or there is no mock server running on that port.

Dependencies

~29–39MB
~859K SLoC