Moxinet (moxinet v0.2.1)

Moxinet helps you mock the internet at the HTTP layer without sacrificing parallel testing.

Summary

Functions

Returns the header needed to be included in requests to the mock servers in order to support parallel runs.

Mocks a call for the passed module when used from a certain pid, defaulting self()

Turns a pid into a reference which could be used for indexing the signatures.

The start functions which will start the Moxinet server.

Types

Link to this type

http_method()

@type http_method() :: :get | :post | :patch | :put | :delete | :options

Functions

Link to this function

build_mock_header(pid \\ self())

@spec build_mock_header(pid()) :: {String.t(), String.t()}

Returns the header needed to be included in requests to the mock servers in order to support parallel runs.

Link to this function

expect(module, http_method, path, callback, from_pid \\ self())

@spec expect(
  module(),
  http_method(),
  binary(),
  Moxinet.SignatureStorage.Mock.callback(),
  pid()
) :: :ok

Mocks a call for the passed module when used from a certain pid, defaulting self()

Link to this function

pid_reference(pid)

@spec pid_reference(pid()) :: String.t()

Turns a pid into a reference which could be used for indexing the signatures.

@spec start(Keyword.t()) :: {:ok, pid()} | {:error, atom()}

The start functions which will start the Moxinet server.

You'd most likely want to put run this function from your test_helper.exs:

{:ok, _pid} = Moxinet.start(router: MyMockServer, port: 4010)

Options

  • router: A reference to your mock server. Required
  • port: The port your mock server will run on. Required
  • name: Name of the moxinet supervisor. Defaults to Moxinet