View Source TestServer (TestServer v0.1.17)
No fuzz ExUnit test server to mock third party services.
Features:
- HTTP/1
- HTTP/2
- WebSocket
- Built-in TLS with self-signed certificates
- Plug route matching
Summary
Functions
Adds a route to the current test server.
Adds a route to a test server instance.
Gets current test server instance if running.
Adds a plug to the current test server.
Adds a route to a test server instance.
Start a test server instance.
Shuts down the current test server.
Shuts down a test server instance.
Produces a URL for current test server.
Produces a URL for a test server instance.
Adds a message handler to a websocket instance.
Sends an message to a websocket instance.
Adds a websocket route to current test server.
Adds a websocket route to a test server.
Fetches the generated x509 suite for the current test server.
Fetches the generated x509 suite for a test server instance.
Types
@type instance() :: pid()
@type route() :: reference()
@type stacktrace() :: list()
@type websocket_reply() :: {:reply, websocket_frame(), websocket_state()} | {:ok, websocket_state()}
@type websocket_state() :: any()
Functions
@spec add(binary()) :: :ok
Adds a route to the current test server.
Options
:via
- matches the route against some specific HTTP method(s) specified as an atom, like:get
or:put
, or a list, like[:get, :post]
.:match
- an anonymous function that will be called to see if a route matches, defaults to matching with arguments of uri and:via
option.:to
- a Plug or anonymous function that will be called when the route matches, defaults to return the http scheme.
Adds a route to a test server instance.
See add/2
for options.
@spec get_instance() :: pid() | nil
Gets current test server instance if running.
Adds a plug to the current test server.
This plug will be called for all requests before route is matched.
Adds a route to a test server instance.
See plug/1
for options.
Start a test server instance.
The instance will be terminated when the test case finishes.
Options
:port
- integer of port number, defaults to random port that can be opened;:scheme
- an atom for the http scheme. Defaults to:http
;:http_server
- HTTP server configuration. Defaults to{TestServer.HTTPServer.Httpd, []}
;:tls
- Passthru options for TLS configuration handled by the webserver;:ipfamily
- The IP address type to use, either:inet
or:inet6
. Defaults to:inet
;
@spec stop() :: :ok | {:error, term()}
Shuts down the current test server.
Shuts down a test server instance.
@spec url() :: binary()
Produces a URL for current test server.
Options
:host
- binary host value, it'll be added to inet for IP127.0.0.1
and::1
, defaults to"localhost"
;
Produces a URL for a test server instance.
See url/2
for options.
@spec websocket_handle(websocket_socket()) :: :ok | {:error, term()}
@spec websocket_handle( websocket_socket(), keyword() ) :: :ok
Adds a message handler to a websocket instance.
Options
:match
- an anonymous function that will be called to see if a message matches, defaults to matching anything.:to
- an anonymous function that will be called when the message matches, defaults to returning received message.
@spec websocket_info(websocket_socket(), function() | nil) :: :ok
Sends an message to a websocket instance.
@spec websocket_init(binary()) :: {:ok, websocket_socket()} | {:error, term()}
@spec websocket_init( binary(), keyword() ) :: {:ok, websocket_socket()}
@spec websocket_init(pid(), binary()) :: {:ok, websocket_socket()}
Adds a websocket route to current test server.
Options
Takes the same options as add/2
, except :to
.
@spec websocket_init(pid(), binary(), keyword()) :: {:ok, websocket_socket()}
Adds a websocket route to a test server.
See websocket_init/2
for options.
@spec x509_suite() :: term()
Fetches the generated x509 suite for the current test server.
Fetches the generated x509 suite for a test server instance.