testutils

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2022 License: Apache-2.0 Imports: 9 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FreezeTime added in v1.4.0

func FreezeTime() func()

FreezeTime to the predetermined time. Returns a function that should be deferred to unfreeze time. Meant for testing.

func Get

func Get(uri string, opts ...ReqOption) (*http.Response, []byte, error)

Get do a GET request.

func MakeRequest

func MakeRequest(uri string, opts ...ReqOption) (*http.Response, []byte, error)

MakeRequest create and do a request.

func NewHandler

func NewHandler(handler http.HandlerFunc) *httptest.Server

NewHandler creates a new Server.

func NewResponder

func NewResponder(response string) *httptest.Server

NewResponder creates a new Server with response.

func ParseURI

func ParseURI(uri string) *url.URL

ParseURI is the version of url.ParseRequestURI that panics if incorrect, helpful to shorten the tests.

func Post

func Post(uri string, opts ...ReqOption) (*http.Response, []byte, error)

Post do a POST request.

Types

type ReqOption

type ReqOption func(o *ReqOpts) error

ReqOption request option type.

func BasicAuth

func BasicAuth(username, password string) ReqOption

BasicAuth sets request basic auth.

func Body

func Body(b string) ReqOption

Body sets request body.

func Header(name, val string) ReqOption

Header sets request header.

func Headers

func Headers(h http.Header) ReqOption

Headers sets request headers.

func Host

func Host(h string) ReqOption

Host sets request host.

func Method

func Method(m string) ReqOption

Method sets request method.

type ReqOpts

type ReqOpts struct {
	Host    string
	Method  string
	Body    string
	Headers http.Header
	Auth    *utils.BasicAuth
}

ReqOpts request options.

Jump to

Keyboard shortcuts

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