httpxtest

package
v0.0.0-...-bfab8ab Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HttpErrorUri   = "proxy://www.httperror.com"
	BodyIOErrorUri = "proxy://www.bodyioerror.com"
)

Variables

This section is empty.

Functions

func BodyIOErrorProxy

func BodyIOErrorProxy(req *http.Request) (*http.Response, error)

BodyIOErrorProxy - reusable body I/O error proxy

func ErrorProxy

func ErrorProxy(req *http.Request) (*http.Response, error)

ErrorProxy - test proxy for http and body I/O errors

func HttpErrorProxy

func HttpErrorProxy(req *http.Request) (*http.Response, error)

HttpErrorProxy - reusable http error proxy

func NewIOErrorResponse

func NewIOErrorResponse() *http.Response

NewIOErrorResponse - create a response that contains a body that will generate an I/O error when read

func NewResponse

func NewResponse(httpStatus int, content []byte, kv ...string) *http.Response

NewResponse - create a new response from the provided parameters

func ParseRaw

func ParseRaw(rawUri string) *url.URL

ParseRaw - parse a raw Uri without error

func Pattern

func Pattern(req *http.Request) string

func ReadContent

func ReadContent(rawHttp []byte) (*bytes.Buffer, error)

func ReadRequest

func ReadRequest(uri *url.URL) (*http.Request, error)

func ReadResponse

func ReadResponse(uri *url.URL) (*http.Response, error)

Types

type Args

type Args struct {
	Item string
	Got  string
	Want string
	Err  error
}

func Content

func Content[T any](got *http.Response, want *http.Response, testBytes func(got *http.Response, gotBytes []byte, want *http.Response, wantBytes []byte) []Args) (failures []Args, content bool, gotT T, wantT T)

func Headers

func Headers(got *http.Response, want *http.Response, names ...string) (failures []Args)

func ReadHttp

func ReadHttp(basePath, reqName, respName string) ([]Args, *http.Request, *http.Response)

type ReaderCloser

type ReaderCloser struct {
	Reader io.Reader
	Err    error
}

ReaderCloser - test type for a body.ReadCloser interface

func NewReaderCloser

func NewReaderCloser(reader io.Reader, err error) *ReaderCloser

func (*ReaderCloser) Close

func (r *ReaderCloser) Close() error

func (*ReaderCloser) Read

func (r *ReaderCloser) Read(p []byte) (int, error)

Jump to

Keyboard shortcuts

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