Passby.Instance (passby v0.1.1)

Copy Markdown View Source

GenServer that manages an individual Passby mock HTTP server instance.

Summary

Functions

Returns a specification to start this module under a supervisor.

Closes the listening socket to simulate network/server downtime.

Adds an expectation that will be invoked for all matching requests.

Adds an expectation that will be invoked at most once.

Clears all expectations from the instance.

Returns the port number the instance is listening on.

Starts a new Passby.Instance linked to the calling process.

Adds a stub handler that matches if no specific expectation matched.

Restarts the listening socket after being taken down.

Types

t()

@type t() :: %Passby.Instance{
  acceptor: pid() | nil,
  bind_address: :inet.ip4_address() | nil,
  caller: pid() | nil,
  expectations: [map()],
  port: :inet.port_number() | nil,
  socket: :gen_tcp.socket() | nil
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

down(server)

@spec down(pid()) :: :ok

Closes the listening socket to simulate network/server downtime.

expect(server, method, path, fun)

@spec expect(pid(), String.t() | nil, String.t() | nil, (Passby.Conn.t() -> any())) ::
  :ok

Adds an expectation that will be invoked for all matching requests.

expect_once(server, method, path, fun)

@spec expect_once(pid(), String.t() | nil, String.t() | nil, (Passby.Conn.t() ->
                                                          any())) :: :ok

Adds an expectation that will be invoked at most once.

pass(server)

@spec pass(pid()) :: :ok

Clears all expectations from the instance.

port(server)

@spec port(pid()) :: :inet.port_number()

Returns the port number the instance is listening on.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts a new Passby.Instance linked to the calling process.

stub(server, method, path, fun)

@spec stub(pid(), String.t() | nil, String.t() | nil, (Passby.Conn.t() -> any())) ::
  :ok

Adds a stub handler that matches if no specific expectation matched.

up(server)

@spec up(pid()) :: :ok

Restarts the listening socket after being taken down.