http

package
v0.14.4 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2023 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete[TSender RequestSender](t testing.TB, app TSender, uri string, modifiers ...RequestModifier) *http.Response

Returns a pointer to http.Response from DELETE request for testing purposes

func Get

func Get[TSender RequestSender](t testing.TB, app TSender, uri string, modifiers ...RequestModifier) *http.Response

Returns a pointer to http.Response from GET request for testing purposes

func MakeRequest

func MakeRequest[T any](t testing.TB, method, uri string, modifiers ...RequestModifier) *http.Request

Provides a way to create a request for testing purposes

func Patch

func Patch[TSender RequestSender, TBody any](t testing.TB, app TSender, uri string, modifiers ...RequestModifier) *http.Response

Returns a pointer to http.Response from PATCH request for testing purposes

func Post

func Post[TSender RequestSender, TBody any](t testing.TB, app TSender, uri string, modifiers ...RequestModifier) *http.Response

Returns a pointer to http.Response from POST request for testing purposes

func Put

func Put[TSender RequestSender, TBody any](t testing.TB, app TSender, uri string, modifiers ...RequestModifier) *http.Response

Returns a pointer to http.Response from PUT request for testing purposes

Types

type RequestModifier

type RequestModifier func(*http.Request) *http.Request

type RequestModifier Delegates http.Request functions

func WithBody

func WithBody[T any](t testing.TB, body T) RequestModifier

Provides a way to set Body of a request for testing purposes

func WithCookies

func WithCookies(t testing.TB, cookies []*http.Cookie) RequestModifier

Provides a way to set Cookies of a request for testing purposes Example:

cookies := []*http.Cookie{
		{Name: "jwt-token"},
	}

WithCookies(t, cookies)

func WithHeaders

func WithHeaders(t testing.TB, headers http.Header) RequestModifier

Provides a way to set Headers of a request for testing purposes

func WithQuery

func WithQuery(t testing.TB, queryMap map[string]string) RequestModifier

Provides a way to put query string params.

WithQuery(map[string]string{
	"id": "mongoid",
})

Returns URL?id=mongoid

type RequestSender

type RequestSender interface {
	io.Closer
	Test(req *http.Request, timeout ...time.Duration) (*http.Response, error)
}

Type RequestSender Sturcture contains in memory HTTP Server and Client for testing purposes

Jump to

Keyboard shortcuts

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