httprecorder

package
v1.0.7010-f7148c9 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package httprecorder provides a simple way of recording and later retrieving all requests that are sent to an HTTP handler.

If you are writing an HTTP client for an external dependency, this is likely what you need to test it is sending the right payloads, etc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IgnoreHeaders

func IgnoreHeaders(headers ...string) gocmp.Option

func OnlyHeaders

func OnlyHeaders(headers ...string) gocmp.Option

Types

type Request

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

func (*Request) Decode

func (r *Request) Decode(x interface{}) error

Decode decodes the JSON from the request into the supplied pointer

func (*Request) StringBody

func (r *Request) StringBody() string

type RequestRecorder

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

func New

func New() *RequestRecorder

func (*RequestRecorder) AllRequests

func (r *RequestRecorder) AllRequests() []Request

func (*RequestRecorder) FindRequests

func (r *RequestRecorder) FindRequests(method string, u url.URL) []Request

func (*RequestRecorder) LastRequest

func (r *RequestRecorder) LastRequest() *Request

func (*RequestRecorder) Record

func (r *RequestRecorder) Record(request *http.Request) (err error)

Record stores a copy of the incoming request ensuring the body can still be consumed by the caller

func (*RequestRecorder) Reset

func (r *RequestRecorder) Reset()

Directories

Path Synopsis
Package ginrecorder provides a middleware to wire a httprecorder into Gin routers used in test fakes.
Package ginrecorder provides a middleware to wire a httprecorder into Gin routers used in test fakes.
Package httpnetrecorder provides a middleware to wire a httprecorder into test fakes.
Package httpnetrecorder provides a middleware to wire a httprecorder into test fakes.

Jump to

Keyboard shortcuts

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