{"modulePath":"github.com/theopenlane/httpsling","version":"v0.3.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package httptestutil\n\nPackage httptestutil contains utilities for use in HTTP tests, particular when using httptest.Server\n\n## Functions\n\n```go\nfunc Dump(ts *httptest.Server, to io.Writer)\n```\nDump writes requests and responses to the writer\n\n```go\nfunc DumpTo(handler http.Handler, writer io.Writer) http.Handler\n```\nDumpTo wraps an http.Handler in a new handler the new handler dumps requests and responses to a writer, using the httputil.DumpRequest and httputil.DumpResponse functions\n\n```go\nfunc DumpToLog(ts *httptest.Server, logf func(a ...any))\n```\nDumpToLog writes requests and responses to a logging function\n\n```go\nfunc DumpToStdout(ts *httptest.Server)\n```\nDumpToStdout writes requests and responses to os.Stdout\n\n```go\nfunc Requester(ts *httptest.Server, options ...httpsling.Option) *httpsling.Requester\n```\nRequester creates a Requester instance which is pre-configured to send requests to the test server\n\n## Types\n\n```go\ntype Exchange struct {\n\t// Request is the request sent to the server\n\tRequest *http.Request\n\t// RequestBody is the request body\n\tRequestBody *bytes.Buffer\n\t// StatusCode is the status code returned by the server\n\tStatusCode int\n\t// Header is the response header\n\tHeader http.Header\n\t// ResponseBody is the response body\n\tResponseBody *bytes.Buffer\n}\n```\nExchange is a snapshot of one request/response exchange with the server\n\n```go\ntype Inspector struct {\n\tExchanges chan Exchange\n}\n```\nInspector is server-side middleware which captures server exchanges in a buffer\n\n```go\nfunc Inspect(ts *httptest.Server) *Inspector\n```\nInspect installs and returns an Inspector; the Inspector captures exchanges with the test server\n\n```go\nfunc NewInspector(size int) *Inspector\n```\nNewInspector creates a new Inspector with the requested channel buffer size\n\n```go\nfunc (b *Inspector) Clear()\n```\nClear drains the channel\n\n```go\nfunc (b *Inspector) Drain() []*Exchange\n```\nDrain reads all buffered exchanges from the channel\n\n```go\nfunc (b *Inspector) LastExchange() *Exchange\n```\nLastExchange receives the most recent exchange from channel; this also has the side effect of draining the channel completely\n\n```go\nfunc (b *Inspector) NextExchange() *Exchange\n```\nNextExchange receives the next exchange from the channel, or returns nil if no exchange is ready\n\n```go\nfunc (b *Inspector) Wrap(next http.Handler) http.Handler\n```\nWrap installs the inspector in an HTTP server by wrapping the server's Handler\n\n","path":"github.com/theopenlane/httpsling/httptestutil","name":"httptestutil","synopsis":"Package httptestutil contains utilities for use in HTTP tests, particular when using httptest.Server","isRedistributable":true}
