Help us shape the future of Go! Take the 2026 Go Developer Survey

testttp

package
v1.10.3 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Req

type Req struct {
	// contains filtered or unexported fields
}

Req is a request builder.

func Delete

func Delete(t testing.TB, addr string) *Req

Delete creates a DELETE request.

func Get

func Get(t testing.TB, addr string) *Req

Get creates a GET request.

func HTTP

func HTTP(t testing.TB, method, addr string, body io.Reader) *Req

HTTP runs creates a request for an http call.

func Patch

func Patch(t testing.TB, addr string, body io.Reader) *Req

Patch creates a PATCH request.

func PatchJSON

func PatchJSON(t testing.TB, addr string, v interface{}) *Req

PatchJSON creates a PATCH request with a json encoded body.

func Post

func Post(t testing.TB, addr string, body io.Reader) *Req

Post creates a POST request.

func PostJSON

func PostJSON(t testing.TB, addr string, v interface{}) *Req

PostJSON returns a POST request with a json encoded body.

func Put

func Put(t testing.TB, addr string, body io.Reader) *Req

Put creates a PUT request.

func PutJSON

func PutJSON(t testing.TB, addr string, v interface{}) *Req

PutJSON creates a PUT request with a json encoded body.

func (*Req) Do

func (r *Req) Do(handler http.Handler) *Resp

Do runs the request against the provided handler.

func (*Req) Headers

func (r *Req) Headers(k, v string, rest ...string) *Req

Headers allows the user to set headers on the http request.

func (*Req) SetFormValue

func (r *Req) SetFormValue(k, v string) *Req

func (*Req) WithCtx

func (r *Req) WithCtx(ctx context.Context) *Req

WithCtx sets the ctx on the request.

func (*Req) WrapCtx

func (r *Req) WrapCtx(fn func(ctx context.Context) context.Context) *Req

WrapCtx provides means to wrap a request context. This is useful for stuffing in the auth stuffs that are required at times.

type Resp

type Resp struct {
	Req *http.Request
	Rec *httptest.ResponseRecorder
	// contains filtered or unexported fields
}

Resp is a http recorder wrapper.

func (*Resp) Debug

func (r *Resp) Debug(b bool) *Resp

Debug sets the debugger. If true, the debugger will print the body of the response when the expected status is not received.

func (*Resp) Expect

func (r *Resp) Expect(fn func(*Resp)) *Resp

Expect allows the assertions against the raw Resp.

func (*Resp) ExpectBody

func (r *Resp) ExpectBody(fn func(body *bytes.Buffer)) *Resp

ExpectBody provides an assertion against the recorder body.

func (*Resp) ExpectHeader

func (r *Resp) ExpectHeader(k, v string) *Resp

ExpectHeader asserts that the header is in the recorder.

func (*Resp) ExpectHeaders

func (r *Resp) ExpectHeaders(h map[string]string) *Resp

ExpectHeaders asserts that multiple headers with values exist in the recorder.

func (*Resp) ExpectStatus

func (r *Resp) ExpectStatus(code int) *Resp

ExpectStatus compares the expected status code against the recorded status code.

Jump to

Keyboard shortcuts

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