http

package
v0.0.0-...-f1836c7 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package http includes useful extensions to the net/http/httptest package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ResponseRecorder

type ResponseRecorder struct {
	*httptest.ResponseRecorder // embed the stdlib ResponseRecorder for API parity
	// contains filtered or unexported fields
}

ResponseRecorder is an augmented version of net.http.httptest.ResponseRecorder with the ability to make various assertions concerning the HTTP response that was observed.

func NewResponseRecorder

func NewResponseRecorder(t *testing.T) *ResponseRecorder

Build a new ResponseRecorder that extends the net/http/httptest one by attaching some functions making it simple to assert some facts about the response or record an error if those assertions fail.

Because the recording is parameterized by a single testing.T this should not be resude between test cases.

func (*ResponseRecorder) AssertBody

func (rr *ResponseRecorder) AssertBody(want string)

Compares the wanted body against what was sent in the response and records an error if they don't match.

func (*ResponseRecorder) AssertBodyJSON

func (rr *ResponseRecorder) AssertBodyJSON(want interface{})

Convenience method that renders an object as json and then compares that to the body sent in the response. If they don't match a test error will be recorded.

func (*ResponseRecorder) AssertHeader

func (rr *ResponseRecorder) AssertHeader(name string, want string)

Fetches the header name's value, compares to want and records an error if they don't match.

func (*ResponseRecorder) AssertNoBody

func (rr *ResponseRecorder) AssertNoBody()

If the response had any body content this will record a test error.

func (*ResponseRecorder) AssertStatus

func (rr *ResponseRecorder) AssertStatus(want int)

If the response did not have the indicated status this records a test error.

func (*ResponseRecorder) GetBody

func (rr *ResponseRecorder) GetBody() []byte

Convenience method that returns the contents of the body.

Jump to

Keyboard shortcuts

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