httptest

package
v0.0.0-...-ed9fe1d Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2018 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRequestFactory = RequestFactoryFunc(http.NewRequest)

DefaultRequestFactory is a RequestFactory on top of http.NewRequest

Functions

This section is empty.

Types

type Assert

type Assert struct {
	*assert.Assert
}

Assert is a wrapper for github.com/speedland/go/x/xtesting/assert.Assert and provides http specific assertions

func NewAssert

func NewAssert(t *testing.T) *Assert

NewAssert returns *Assert

func (*Assert) Body

func (a *Assert) Body(expected string, res *httptest.ResponseRecorder, msgContext ...interface{})

Body asserts the body string

func (*Assert) Cookie

func (a *Assert) Cookie(res *httptest.ResponseRecorder, name string, msgContext ...interface{}) *http.Cookie

Cookie asserts the cookie name and extract it as *http.Cookie

func (*Assert) Header

func (a *Assert) Header(expected string, res *httptest.ResponseRecorder, fieldName string, msgContext ...interface{})

Header asserts the header value

func (*Assert) JSON

func (a *Assert) JSON(v interface{}, res *httptest.ResponseRecorder, msgContext ...interface{})

JSON asserts the body string as as json and returns the result as interface{}

func (*Assert) Status

func (a *Assert) Status(expected response.HTTPStatus, res *httptest.ResponseRecorder, msgContext ...interface{})

Status asserts the http status code

type Recorder

type Recorder struct {
	Cookies []*http.Cookie
	// contains filtered or unexported fields
}

Recorder is a test recorder.

func NewRecorder

func NewRecorder(handler http.Handler) *Recorder

NewRecorder returns a new *Recorder

func NewRecorderWithFactory

func NewRecorderWithFactory(handler http.Handler, factory RequestFactory) *Recorder

NewRecorderWithFactory returns a new *Recorder with the custom factory configuration

func (*Recorder) NewRequest

func (r *Recorder) NewRequest(method, path string, v interface{}) *http.Request

NewRequest returns http.Request with request body given by `v`

func (*Recorder) TestDelete

func (r *Recorder) TestDelete(path string) *httptest.ResponseRecorder

TestDelete make a test DELETE request to the router and returns the response as *http.ResponseRecorder

func (*Recorder) TestGet

func (r *Recorder) TestGet(path string) *httptest.ResponseRecorder

TestGet make a test GET request to the router and returns the response as *http.ResponseRecorder

func (*Recorder) TestPost

func (r *Recorder) TestPost(path string, v interface{}) *httptest.ResponseRecorder

TestPost make a test POST request to the router and returns the response as *http.ResponseRecorder

func (*Recorder) TestPut

func (r *Recorder) TestPut(path string, v interface{}) *httptest.ResponseRecorder

TestPut make a test PUT request to the router and returns the response as *http.ResponseRecorder

func (*Recorder) TestRequest

func (r *Recorder) TestRequest(req *http.Request) *httptest.ResponseRecorder

TestRequest make a test request to the router and returns the response as *http.ResponseRecorder

type RequestFactory

type RequestFactory interface {
	NewRequest(string, string, io.Reader) (*http.Request, error)
}

RequestFactory is an interface to create a new request.

type RequestFactoryFunc

type RequestFactoryFunc func(string, string, io.Reader) (*http.Request, error)

RequestFactoryFunc is a wrapper to NewRequest function to be RequestFactory

func (RequestFactoryFunc) NewRequest

func (f RequestFactoryFunc) NewRequest(method string, path string, body io.Reader) (*http.Request, error)

NewRequest implements RequestFactory#NewRequest

Jump to

Keyboard shortcuts

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