httpclienttest

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package httpclienttest provides a recording HTTP transport for tests.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnexpectedRequest = errors.New("httpclienttest: unexpected request")

ErrUnexpectedRequest identifies a request with no remaining stubbed response.

Functions

This section is empty.

Types

type Request

type Request struct {
	Method string
	URL    string
	Header http.Header
	Body   []byte
}

Request records the method, URL, headers, and body passed to the transport.

type Response

type Response struct {
	StatusCode int
	Header     http.Header
	Body       []byte
	Err        error
}

Response describes one reply in a transport's response sequence. A zero StatusCode means 200 OK. Err simulates a transport failure.

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

Transport records requests and serves configured replies in order. A Transport is ready to use as a zero value and is safe for concurrent use.

func (*Transport) Requests

func (transport *Transport) Requests() []Request

Requests returns independent copies of recorded requests in arrival order.

func (*Transport) Respond

func (transport *Transport) Respond(method, target string, replies ...Response)

Respond appends replies for a method and an exact absolute URL or request URI. A request URI includes its query string. An absolute URL match takes priority. Each request consumes one reply.

func (*Transport) RoundTrip

func (transport *Transport) RoundTrip(request *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper and consumes one configured reply.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL