Crate pact_mock_server_ffi[][src]

Expand description

The pact_mock_server crate provides a number of exported functions using C bindings for controlling the mock server. These can be used in any language that supports C bindings.

create_mock_server

External interface to create a mock server. A pointer to the pact JSON as a C string is passed in, 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.

IMPORTANT NOTE: The JSON string for the result is allocated on the rust heap, and will have to be freed once the code using the mock server is complete. The cleanup_mock_server function is provided for this purpose. If the mock server is not cleaned up properly, this will result in memory leaks as the rust heap will not be reclaimed.

cleanup_mock_server

This function will try terminate the mock server with the given port number and cleanup any memory allocated for it by the mock_server_mismatches function. Returns true, unless a mock server with the given port number does not exist, or the function fails in some way.

NOTE: Although close() on the listerner for the mock server is called, this does not currently work and the listerner will continue handling requests. In this case, it will always return a 501 once the mock server has been cleaned up.

write_pact_file

External interface to 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 a NULL pointer is passed, the current working directory is used.

Returns 0 if the pact file was successfully written. Returns a positive code if the file can not be written, or there is no mock server running on that port or the function panics.

Modules

Functions to support processing request/response bodies

Handles wrapping Rust models

Enums

Result of wrapping a string value

Functions

Checks that the example string matches the given regex

External interface to cleanup a mock server. This function will try terminate the mock server with the given port number and cleanup any memory allocated for it. Returns true, unless a mock server with the given port number does not exist, or the function panics.

External interface to create a mock server. A pointer to the pact JSON as a C string is passed in, 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.

External interface to create a mock server. A Pact handle is passed in, 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.

Fetch the in-memory logger buffer contents. This will only have any contents if the buffer sink has been configured to log to. The contents will be allocated on the heap and will need to be freed with string_delete.

Frees the memory allocated to a string by another function

Generates a datetime value from the provided format string, using the current system date and time NOTE: The memory for the returned string needs to be freed with the free_string function

Generates an example string based on the provided regex. NOTE: The memory for the returned string needs to be freed with the free_string function

Generates an example string based on the provided regex.

Fetch the CA Certificate used to generate the self-signed certificate for the TLS mock server.

Adds a provider state to the Interaction. Returns false if the interaction or Pact can’t be modified (i.e. the mock server for it has already started)

Adds a provider state to the Interaction with a parameter key and value. Returns false if the interaction or Pact can’t be modified (i.e. the mock server for it has already started)

Initialise the mock server library, can provide an environment variable name to use to set the log levels.

Initialises logging, and sets the log level explicitly.

Log using the shared core logging facility.

Convenience function to direct all logging to a thread local memory buffer.

Convenience function to direct all logging to a file.

Convenience function to direct all logging to stderr.

Convenience function to direct all logging to stdout.

Apply the thread-local logger to the program.

Attach an additional sink to the thread-local logger.

Initialize the thread-local logger with no sinks.

Sets the description for the Message.

Adds a provider state to the Interaction.

Adds a provider state to the Message with a parameter key and value.

Reifies the given message

Adds the contents of the Message.

Adds expected metadata to the Message

Fetch the logs for the mock server. This needs the memory buffer log sink to be setup before the mock server is started. Returned string will be freed with the cleanup_mock_server function call.

External interface 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, or the method panics.

External interface to get all the mismatches from a mock server. The port number of the mock server is passed in, and a pointer to a C string with the mismatches in JSON format is returned.

Creates a new Interaction and returns a handle to it.

Creates a new Message and returns a handle to it.

Creates a new Pact Message model and returns a handle to it.

Creates a new Pact model and returns a handle to it.

Configures the response for the Interaction. Returns false if the interaction or Pact can’t be modified (i.e. the mock server for it has already started)

Sets the description for the Interaction. Returns false if the interaction or Pact can’t be modified (i.e. the mock server for it has already started)

Get the current library version

Adds a binary file as the body with the expected content type and example contents. Will use a mime type matcher to match the body. Returns false if the interaction or Pact can’t be modified (i.e. the mock server for it has already started)

Adds the body for the interaction. Returns false if the interaction or Pact can’t be modified (i.e. the mock server for it has already started)

Configures a header for the Interaction. Returns false if the interaction or Pact can’t be modified (i.e. the mock server for it has already started)

Sets the additional metadata on the Pact file. Common uses are to add the client library details such as the name and version

Adds a binary file as the body as a MIME multipart with the expected content type and example contents. Will use a mime type matcher to match the body. Returns an error if the interaction or Pact can’t be modified (i.e. the mock server for it has already started)

Sets the additional metadata on the Pact file. Common uses are to add the client library details such as the name and version Returns false if the interaction or Pact can’t be modified (i.e. the mock server for it has already started)

Configures a query parameter for the Interaction. Returns false if the interaction or Pact can’t be modified (i.e. the mock server for it has already started)

Configures the request for the Interaction. Returns false if the interaction or Pact can’t be modified (i.e. the mock server for it has already started)

Sets the specification version for a given Pact model. Returns false if the interaction or Pact can’t be modified (i.e. the mock server for it has already started)

External interface to write out the message 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 a NULL pointer is passed, the current working directory is used.

External interface to 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 a NULL pointer is passed, the current working directory is used.