testutils

package
v0.0.0-...-7d77d5e Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeJSONBody

func DecodeJSONBody[T any](t *testing.T, req *http.Request) *T

DecodeJSONBody implements a testing util to let you easily decode request bodies in test middleware

func DecodeRawBody

func DecodeRawBody(t *testing.T, req *http.Request) string

DecodeJSONBody implements a testing util to let you easily decode raw request bodies in test middleware

func Middleware

func Middleware(it RoundTripInterceptor) http.RoundTripper

Middleware creates a new interceptor middleware for a http transport

func WithoutQuery

func WithoutQuery(u *url.URL) string

WithoutQuery returns the URL without a query string appended to it

Types

type Response

type Response struct {
	Body    []byte
	Error   error
	Headers http.Header
	Status  int
}

Response wraps the roundtripper responses

func EmptyResponse

func EmptyResponse(status int) *Response

EmptyResponse creates a new empty response

func ErrorResponse

func ErrorResponse(err error) *Response

ErrorResponse returns a new error response

func JSONResponse

func JSONResponse(t *testing.T, status int, jsonBody interface{}) *Response

JSONResponse creates a new JSON response

func (*Response) SetHeader

func (r *Response) SetHeader(key, value string) *Response

SetHeader adds a new header to the response

type RoundTripInterceptor

type RoundTripInterceptor func(r *http.Request) *Response

RoundTripInterceptor will intercept the HTTP client call and let you send your own response

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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