testutil

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterResponseHandler

func RegisterResponseHandler(mime string, handler ResponseHandler)

RegisterResponseHandler registers handler.

Types

type CompletedRequest

type CompletedRequest struct {
	Recorder *httptest.ResponseRecorder

	// When set to true, decoders will be more strict. In the default JSON
	// recorder, unknown fields will cause errors.
	Strict bool
}

CompletedRequest represents the returned request with some helper functions.

func (*CompletedRequest) Code

func (c *CompletedRequest) Code() int

Code returns the response code.

func (*CompletedRequest) DisallowUnknownFields

func (c *CompletedRequest) DisallowUnknownFields()

DisallowUnknownFields makes the unmarshaler strict.

func (*CompletedRequest) UnmarshalBodyToObject

func (c *CompletedRequest) UnmarshalBodyToObject(obj interface{}) error

UnmarshalBodyToObject unmarshales the response body.

func (*CompletedRequest) UnmarshalJSONToObject

func (c *CompletedRequest) UnmarshalJSONToObject(obj interface{}) error

UnmarshalJSONToObject unmarshals the resposne body.

type RequestBuilder

type RequestBuilder struct {
	Method  string
	Path    string
	Headers map[string]string
	Body    []byte
	Error   error
	Cookies []*http.Cookie
}

RequestBuilder caches request settings as we build up the request.

func NewRequest

func NewRequest() *RequestBuilder

NewRequest makes a new request.

func (*RequestBuilder) Delete

func (r *RequestBuilder) Delete(path string) *RequestBuilder

Delete does the request with the DELETE method.

func (*RequestBuilder) Get

func (r *RequestBuilder) Get(path string) *RequestBuilder

Get does the request with the GET Method.

func (*RequestBuilder) GoWithHTTPHandler

func (r *RequestBuilder) GoWithHTTPHandler(t *testing.T, handler http.Handler) *CompletedRequest

GoWithHTTPHandler performs the request, it takes a pointer to a testing context to print messages, and a http handler for request handling.

func (*RequestBuilder) Patch

func (r *RequestBuilder) Patch(path string) *RequestBuilder

Patch does the request method with the PATCH method.

func (*RequestBuilder) Post

func (r *RequestBuilder) Post(path string) *RequestBuilder

Post does the request with the POST Method.

func (*RequestBuilder) Put

func (r *RequestBuilder) Put(path string) *RequestBuilder

Put does the request with the PUT method.

func (*RequestBuilder) WithAccept

func (r *RequestBuilder) WithAccept(value string) *RequestBuilder

WithAccept sets teh accept header on r.

func (*RequestBuilder) WithAcceptJSON

func (r *RequestBuilder) WithAcceptJSON() *RequestBuilder

WithAcceptJSON sets the accept header to accept json on r.

func (*RequestBuilder) WithBody

func (r *RequestBuilder) WithBody(body []byte) *RequestBuilder

WithBody sets the body on r.

func (*RequestBuilder) WithContentType

func (r *RequestBuilder) WithContentType(value string) *RequestBuilder

WithContentType sets the Content Type on r.

func (*RequestBuilder) WithCookie

func (r *RequestBuilder) WithCookie(c *http.Cookie) *RequestBuilder

WithCookie sets the cookie on r.

func (*RequestBuilder) WithCookieNameValue

func (r *RequestBuilder) WithCookieNameValue(name, value string) *RequestBuilder

WithCookieNameValue builds a cookie and adds it to r.

func (*RequestBuilder) WithHeader

func (r *RequestBuilder) WithHeader(header, value string) *RequestBuilder

WithHeader sets the header on r.

func (*RequestBuilder) WithHost

func (r *RequestBuilder) WithHost(value string) *RequestBuilder

WithHost sets the Host header on r.

func (*RequestBuilder) WithJSONBody

func (r *RequestBuilder) WithJSONBody(obj interface{}) *RequestBuilder

WithJSONBody sets the body content and marshals obj as JSON.

func (*RequestBuilder) WithJSONContentType

func (r *RequestBuilder) WithJSONContentType() *RequestBuilder

WithJSONContentType sets the content type to json on r.

func (*RequestBuilder) WithJWSAuth

func (r *RequestBuilder) WithJWSAuth(jws string) *RequestBuilder

WithJWSAuth sets the authorization token on r.

func (*RequestBuilder) WithMethod

func (r *RequestBuilder) WithMethod(method string, path string) *RequestBuilder

WithMethod sets the method and path for an operation.

type ResponseHandler

type ResponseHandler func(contentType string, raw io.Reader, obj interface{}, strict bool) error

ResponseHandler is the signature for tests handling responses.

Jump to

Keyboard shortcuts

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