Documentation ¶
Index ¶
- func ValidateErrors(expected, result ServerError) error
- type JSONResponse
- func (r *JSONResponse[T]) Body() string
- func (r *JSONResponse[T]) Status() int
- func (expected *JSONResponse[T]) Validate(result *JSONResponse[T]) error
- func (r *JSONResponse[T]) WithFailure(status int, val *T) *JSONResponse[T]
- func (r *JSONResponse[T]) WithStatus(status int) *JSONResponse[T]
- func (r *JSONResponse[T]) WithSuccess(val *T) *JSONResponse[T]
- func (r *JSONResponse[T]) WithValidationFunc(f func(expected, result T) error) *JSONResponse[T]
- type PathParamType
- type RawResponse
- type Request
- func (r *Request) Context() context.Context
- func (r *Request) Result() *http.Response
- func (r *Request) SetHeader(key, value string) *Request
- func (r *Request) WithContext(ctx context.Context) *Request
- func (r *Request) WithHeaders(vals map[string]string) *Request
- func (r *Request) WithPathParams(ptype PathParamType, vals map[string]string) *Request
- func (r *Request) WithValues(vals map[string]interface{}) *Request
- type Response
- type ServerError
- type TestStruct
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateErrors ¶
func ValidateErrors(expected, result ServerError) error
Types ¶
type JSONResponse ¶
type JSONResponse[T any] struct { Val *T // contains filtered or unexported fields }
func NewJSONResponse ¶
func NewJSONResponse[T any]() *JSONResponse[T]
func ToJSONResponse ¶
func ToJSONResponse[T any](res *http.Response) (*JSONResponse[T], error)
ToJSONResponse takes a httpResponse and maps it to a JSONResponse object It saves the status and parses the body into the expected type It will return an error if the http.Response is not a 200
func (*JSONResponse[T]) Body ¶
func (r *JSONResponse[T]) Body() string
func (*JSONResponse[T]) Status ¶
func (r *JSONResponse[T]) Status() int
func (*JSONResponse[T]) Validate ¶
func (expected *JSONResponse[T]) Validate(result *JSONResponse[T]) error
Validate performs validation for two JSON Responses
func (*JSONResponse[T]) WithFailure ¶
func (r *JSONResponse[T]) WithFailure(status int, val *T) *JSONResponse[T]
func (*JSONResponse[T]) WithStatus ¶
func (r *JSONResponse[T]) WithStatus(status int) *JSONResponse[T]
func (*JSONResponse[T]) WithSuccess ¶
func (r *JSONResponse[T]) WithSuccess(val *T) *JSONResponse[T]
func (*JSONResponse[T]) WithValidationFunc ¶
func (r *JSONResponse[T]) WithValidationFunc(f func(expected, result T) error) *JSONResponse[T]
type PathParamType ¶
type PathParamType int64
const (
Chi PathParamType = iota
)
func (PathParamType) String ¶
func (s PathParamType) String() string
type RawResponse ¶
type RawResponse struct {
// contains filtered or unexported fields
}
func NewRawResponse ¶
func NewRawResponse() *RawResponse
func ToResponse ¶
func ToResponse(res *http.Response) (*RawResponse, error)
ToResponse takes a httpResponse and maps it to a JSONResponse object It saves the status and saves the body
func (*RawResponse) Body ¶
func (r *RawResponse) Body() string
func (*RawResponse) Status ¶
func (r *RawResponse) Status() int
func (*RawResponse) WithBody ¶
func (r *RawResponse) WithBody(body string) *RawResponse
func (*RawResponse) WithStatus ¶
func (r *RawResponse) WithStatus(status int) *RawResponse
type Request ¶
type Request struct { W *httptest.ResponseRecorder R *http.Request }
func NewRequest ¶
NewRequest creates a wrapper object around objects necessary to do a mock http request
func (*Request) WithHeaders ¶
WithHeaders sets HTTP Header for wrapper object
func (*Request) WithPathParams ¶
func (r *Request) WithPathParams(ptype PathParamType, vals map[string]string) *Request
With path params sets path params for the request The PathParamType denotes the routing package used to store path params
func (*Request) WithValues ¶
Inserts each key/value pair into context that gets inserted into the Request