Crate pact_stub_server

Crate pact_stub_server 

Source
Expand description

§Standalone Pact Stub Server

This project provides a server that can generate responses based on pact files. It is a single executable binary. It implements the V4 Pact specification.

Online rust docs

The stub server works by taking all the interactions (requests and responses) from a number of pact files. For each interaction, it will compare any incoming request against those defined in the pact files. If there is a match (based on method, path and query parameters), it will return the response from the pact file.

§Command line interface

The pact stub server is bundled as a single binary executable pact-stub-server. Running this with out any options displays the standard help.

Pact Stub Server 0.5.2

Usage: pact-stub-server [OPTIONS]

Options:
  -l, --loglevel <loglevel>
          Log level (defaults to info) [default: info] [possible values: error, warn, info, debug, trace, none]
  -f, --file <file>
          Pact file to load (can be repeated)
  -d, --dir <dir>
          Directory of pact files to load (can be repeated)
  -e, --extension <ext>
          File extension to use when loading from a directory (default is json)
  -u, --url <url>
          URL of pact file to fetch (can be repeated)
  -b, --broker-url <broker-url>
          URL of the pact broker to fetch pacts from [env: PACT_BROKER_BASE_URL=]
      --user <user>
          User and password to use when fetching pacts from URLS or Pact Broker in user:password form
  -t, --token <token>
          Bearer token to use when fetching pacts from URLS or Pact Broker
  -p, --port <port>
          Port to run on (defaults to random port assigned by the OS)
  -o, --cors
          Automatically respond to OPTIONS requests and return default CORS headers
      --cors-referer
          Set the CORS Access-Control-Allow-Origin header to the Referer
      --insecure-tls
          Disables TLS certificate validation
  -s, --provider-state <provider-state>
          Provider state regular expression to filter the responses by
      --provider-state-header-name <provider-state-header-name>
          Name of the header parameter containing the provider state to be used in case multiple matching interactions are found
      --empty-provider-state
          Include empty provider states when filtering with --provider-state
     --consumer-name <consumer-name>
          Consumer name to use to filter the Pacts fetched from the Pact broker (can be repeated)
      --provider-name <provider-name>
          Provider name to use to filter the Pacts fetched from the Pact broker (can be repeated)
  -v, --version
          Print version information
  -h, --help
          Print help information

§Options

§Log Level

You can control the log level with the -l, --loglevel <loglevel> option. It defaults to info, and the options that you can specify are: error, warn, info, debug, trace, none.

§Pact File Sources

You can specify the pacts to verify with the following options. They can be repeated to set multiple sources.

OptionTypeDescription
-f, --file <file>FileLoads a pact from the given file
-u, --url <url>URLLoads a pact from a URL resource
-d, --dir <dir>DirectoryLoads all the pacts from the given directory
-b, --broker-url <broker-url>URLLoads all the pacts from the Pact broker

§Server Options

The running server can be controlled with the following options:

OptionDescription
-p, --port <port>The port to bind to. If not specified, a random port will be allocated by the operating system.

Enums§

PactSource
Source for loading pacts

Functions§

build_args
Creates a new clap Command instance with the command line arguments for the stub server. This function defines the command line interface for the stub server, including options for logging, pact file sources, and server configuration.
handle_command_args
Handles the command line arguments and runs the stub server accordingly.
print_version
process_stub_command
Handles the command line arguments and runs the stub server accordingly.