testhttpapi

package
v0.5.612 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultHandler

func DefaultHandler(w http.ResponseWriter, r *http.Request)

func GetRequestTestHandler

func GetRequestTestHandler(t testing.TB, expectationStore ExpectationStore, handler http.HandlerFunc) http.HandlerFunc

func NewURL

func NewURL(scheme, host, path string) *url.URL

func SetupHTTPCallHeavyweight

func SetupHTTPCallHeavyweight(t testing.TB, expectationStore ExpectationStore, handlerFunc http.HandlerFunc, roundTripper http.RoundTripper)

func StartServer

func StartServer(t testing.TB, expectations ExpectationStore)

func ValidateHTTPResponseAndErr

func ValidateHTTPResponseAndErr(t *testing.T, response *http.Response, err error)

Types

type ExpectationList

type ExpectationList struct {
	Pos int
	Ex  []HTTPRequestExpectations
	// contains filtered or unexported fields
}

type ExpectationStore

type ExpectationStore map[string]*ExpectationList

func NewExpectationStore

func NewExpectationStore(tokenCalls int) ExpectationStore

func NewExpectationStoreNoToken

func NewExpectationStoreNoToken() ExpectationStore

func (ExpectationStore) Get

func (ExpectationStore) HasKey

func (ex ExpectationStore) HasKey(k string) bool

func (ExpectationStore) Keys

func (ex ExpectationStore) Keys() []string

func (ExpectationStore) Put

type HTTPRequestExpectations

type HTTPRequestExpectations struct {
	Body                 io.ReadCloser
	Header               http.Header
	Method               string
	URL                  *url.URL
	Host                 string
	ResponseExpectations HTTPResponseExpectations
}

func NewHTTPRequestExpectations

func NewHTTPRequestExpectations(body io.ReadCloser, header http.Header, method string, url *url.URL, host string, responseBody string, reponseHeader http.Header) HTTPRequestExpectations

type HTTPResponseExpectations

type HTTPResponseExpectations struct {
	Body   string
	Header http.Header
}

type HandlerTransport

type HandlerTransport struct {
	Handler             http.Handler
	ResponseTransformer func(response *http.Response) *http.Response
}

func NewHandlerTransport

func NewHandlerTransport(handler http.Handler, responseTransformer func(response *http.Response) *http.Response) HandlerTransport

func (HandlerTransport) RoundTrip

func (t HandlerTransport) RoundTrip(req *http.Request) (*http.Response, error)

type PipeResponseWriter

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

func (*PipeResponseWriter) Header

func (w *PipeResponseWriter) Header() http.Header

func (*PipeResponseWriter) Write

func (w *PipeResponseWriter) Write(p []byte) (int, error)

func (*PipeResponseWriter) WriteHeader

func (w *PipeResponseWriter) WriteHeader(status int)

type RewriteTransport

type RewriteTransport struct {
	Transport http.RoundTripper
	URL       *url.URL
}

RewriteTransport is an http.RoundTripper that rewrites requests using the provided URL's Scheme and Host, and its Path as a prefix. The Opaque field is untouched. If Transport is nil, http.DefaultTransport is used.

func NewRewriteTransport

func NewRewriteTransport(transport http.RoundTripper, url *url.URL) RewriteTransport

func (RewriteTransport) RoundTrip

func (t RewriteTransport) RoundTrip(req *http.Request) (*http.Response, error)

type SimulatedRoundTripper

type SimulatedRoundTripper struct {
	T            testing.TB
	Expectations ExpectationStore
	RoundTripper func(*http.Request) (*http.Response, error)
	Strict       bool
}

func NewSimulatedRoundTripper

func NewSimulatedRoundTripper(t testing.TB, expectations ExpectationStore, roundTripper func(*http.Request) (*http.Response, error), strict bool) SimulatedRoundTripper

func (SimulatedRoundTripper) RoundTrip

func (srt SimulatedRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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