HttpDouble.MockRule (http_double v1.0.0)

Copy Markdown View Source

Representation of a mock or expectation rule for HTTP requests.

Rules are evaluated by HttpDouble.MockEngine and can match on method, path, host, query, headers, body, connection id and call index, or use arbitrary predicate functions.

Summary

Types

Rule kind.

Metadata provided to predicate functions and callbacks.

t()

Internal struct type.

Functions

Builds a rule from a keyword options list.

Produces metadata from a request and optional call index.

Types

kind()

@type kind() :: :stub | :expect

Rule kind.

meta()

@type meta() :: %{conn_id: non_neg_integer(), call_index: non_neg_integer()}

Metadata provided to predicate functions and callbacks.

t()

@type t() :: %HttpDouble.MockRule{
  call_range: Range.t() | nil,
  conn_ids: [non_neg_integer()] | nil,
  id: reference(),
  kind: kind(),
  matcher: term(),
  max_calls: :infinity | non_neg_integer(),
  respond: HttpDouble.response_spec(),
  times_used: non_neg_integer()
}

Internal struct type.

Functions

build(kind, opts)

@spec build(kind(), Keyword.t()) :: t()

Builds a rule from a keyword options list.

Supported options:

  • :matcher – see HttpDouble.matcher/0
  • :respond – response specification
  • :conn_id / :conn_ids – restrict to specific connection(s)
  • :call_range – restrict to a specific range of call indices
  • :max_calls – maximum number of times the rule may match

meta_from_request(request, call_index)

@spec meta_from_request(HttpDouble.Request.t(), non_neg_integer() | nil) :: meta()

Produces metadata from a request and optional call index.