livery_test_adapter (livery v0.2.0)

View Source

In-memory adapter used by tests and the parity suite.

Implements livery_adapter against an ETS-backed capture store instead of a real socket. Callers can build a synthetic request, run a middleware stack and handler against it, and inspect the emitted status, headers, body chunks, and trailers without touching a wire.

Response emission is delegated to livery:emit/3, the shared walker that every adapter calls back into.

Summary

Types

capture()

-opaque capture()

listener()

-type listener() :: ets:tid().

stream()

-type stream() :: {listener(), reference()}.

Functions

body/1

-spec body(capture()) -> binary().

body_chunks/1

-spec body_chunks(capture()) -> [iodata()].

capabilities/1

-spec capabilities(listener()) -> livery_adapter:capabilities().

capture/1

-spec capture(stream()) -> capture() | undefined.

end_stream/1

-spec end_stream(capture()) -> boolean().

feed_body(Ref, Pid, Event)

-spec feed_body(reference(),
                pid(),
                {data, iodata()} | {trailers, [{binary(), binary()}]} | eof | {reset, term()}) ->
                   ok.

Push a body chunk (or terminal marker) into the per-request process mailbox in the livery_body protocol.

header/2

-spec header(binary(), capture()) -> binary() | undefined.

headers/1

-spec headers(capture()) -> [{binary(), binary()}].

new_stream(Tab)

-spec new_stream(listener()) -> stream().

new_stream(Tab, Meta)

-spec new_stream(listener(), map()) -> stream().

peer_info(Stream)

-spec peer_info(stream()) -> livery_adapter:peer_info().

reset/2

-spec reset(stream(), term()) -> ok.

reset_reason/1

-spec reset_reason(capture()) -> undefined | term().

run(Stack, Handler, Spec)

Drive a request through a middleware stack and handler.

Spec is a map of #livery_req{} fields. Returns the captured response. Listener lifecycle is managed for the caller.

run(Stack, Handler, Spec, Opts)

send_data/3

-spec send_data(stream(), iodata(), livery_adapter:send_opts()) -> ok.

send_headers/4

-spec send_headers(stream(), 100..599, [{binary(), binary()}], livery_adapter:send_opts()) -> ok.

send_trailers/2

-spec send_trailers(stream(), [{binary(), binary()}]) -> ok.

start()

-spec start() -> listener().

start(Name, Spec, Opts)

-spec start(atom(), term(), map()) -> {ok, listener()}.

status/1

-spec status(capture()) -> undefined | 100..599.

stop(Tab)

-spec stop(listener()) -> ok.

trailers/1

-spec trailers(capture()) -> undefined | [{binary(), binary()}].