Module dropshot::test_util

source ·
Expand description

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

Structs§

  • 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.
  • Analogous to a BunyanLogRecord, but where all fields are optional.
  • ClientTestContext encapsulates several facilities associated with using an HTTP client for testing.
  • 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 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.

Constants§

Functions§

  • Iterate a paginated collection.
  • Returns a unique path name in a temporary directory that includes the given test_name.
  • Returns a unique prefix for log files generated by other processes.
  • Issues an HTTP DELETE to the specified object URL to delete an object.
  • Fetches a single resource from the API.
  • Issues an HTTP PUT to the specified collection URL to update an object.
  • Fetches a list of resources from the API.
  • Fetches a page of resources from the API.
  • Issues an HTTP POST to the specified collection URL to create an object.
  • Read a file containing a Bunyan-format log, returning an array of records.
  • 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.
  • Given a Hyper Response, extract and parse the Content-Length header.
  • 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.
  • 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.
  • Given a Hyper Response whose body is expected to be a UTF-8-encoded string, asynchronously read the body.
  • 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 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.