[][src]Module dropshot::test_util

Automated testing facilities. These are intended for use both by this crate and dependents of this crate.

Structs

BunyanLogRecord

Represents a Bunyan log record. This form does not support any non-standard fields. "level" is not yet supported because we don't (yet) need it.

BunyanLogRecordSpec

Analogous to a BunyanLogRecord, but where all fields are optional.

ClientTestContext

ClientTestContext encapsulates several facilities associated with using an HTTP client for testing.

LogContext

Constructs a Logger for use by a test suite. If a file-based logger is requested, the file will be put in a temporary directory and the name will be unique for a given test name and is likely to be unique across multiple runs of this test. The file will also be deleted if the test succeeds, indicated by invoking LogContext::cleanup_successful. This way, you can debug a test failure from the failed instance rather than hoping the failure is reproducible.

TestContext

TestContext is used to manage a matched server and client for the common test-case pattern of setting up a logger, server, and client and tearing them all down at the end.

Functions

iter_collection

Iterate a paginated collection.

log_file_for_test

Returns a unique path name in a temporary directory that includes the given test_name.

object_get

Fetches a single resource from the API.

objects_list

Fetches a list of resources from the API.

objects_list_page

Fetches a page of resources from the API.

objects_post

Issues an HTTP POST to the specified collection URL to create an object.

read_bunyan_log

Read a file containing a Bunyan-format log, returning an array of records.

read_config

Load an object of type T (usually a hunk of configuration) from the string contents. label is used as an identifying string in a log message. It should be unique for each test.

read_json

Given a Hyper response whose body is expected to be a JSON object that should be parseable via Serde as type T, asynchronously read the body of the response and parse it, returning an instance of T.

read_ndjson

Given a Hyper Response whose body is expected to represent newline-separated JSON, each line of which is expected to be parseable via Serde as type T, asynchronously read the body of the response and parse it accordingly, returning a vector of T.

read_string

Given a Hyper Response whose body is expected to be a UTF-8-encoded string, asynchronously read the body.

verify_bunyan_records

Verify that the key fields of the log records emitted by iter match the corresponding values in expected. Fields that are None in expected will not be checked.

verify_bunyan_records_sequential

Verify that the Bunyan records emitted by iter are chronologically sequential and after maybe_time_before and before maybe_time_after, if those latter two parameters are specified.