testutil

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertHandlerFunc

func AssertHandlerFunc(t *testing.T, request *http.Request, handlerFunc func(http.ResponseWriter, *http.Request), assertResponse func(response *http.Response, responseBody string)) error

AssertHandlerFunc test a request handler func with a test http request, see CreateIncomingRequest

func AssertResponseOfRequestCall

func AssertResponseOfRequestCall(t *testing.T, request *http.Request, assertResponse func(response *http.Response, responseBody string)) error

AssertResponseOfRequestCall test a http request

func AssertResponseStatusOfRequestCall

func AssertResponseStatusOfRequestCall(t *testing.T, request *http.Request, expectedResponseStatus int) error

AssertResponseStatusOfRequestCall test a http request

func CreateIncomingErrorReadingBodyRequest

func CreateIncomingErrorReadingBodyRequest(method, path string, header Header) *http.Request

CreateIncomingErrorReadingBodyRequest create test http request which fails when reading the request body

func CreateIncomingRequest

func CreateIncomingRequest(method, path string, header Header, body string) *http.Request

CreateIncomingRequest create test http request for a an input in a request handler func

func CreateOutgoingRequest

func CreateOutgoingRequest(t *testing.T, method, path string, header Header, body string) *http.Request

CreateOutgoingRequest creates a http request

func RandString

func RandString(n int) string

RandString create a random string with n letters

func RunAndCheckCoverage

func RunAndCheckCoverage(testPackage string, m *testing.M, treshold float64) int

RunAndCheckCoverage use this in order to let the test fail when a coverage is not reached

func StartServing

func StartServing(router *mux.Router)

StartServing creates httptest.Server

func StopServing

func StopServing()

StopServing close httptest.Server

Types

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

Header type for http header

func CreateHeader

func CreateHeader() Header

CreateHeader creates a http header

func (Header) WithAuth

func (h Header) WithAuth(username, password string) Header

WithAuth adds BasicAuth to the header

func (Header) WithJSONAccept

func (h Header) WithJSONAccept() Header

WithJSONAccept adds JSON Accept to the header

func (Header) WithJSONContentType

func (h Header) WithJSONContentType() Header

WithJSONContentType adds JSON Content-Type to the header

func (Header) WithKeyValue

func (h Header) WithKeyValue(key, value string) Header

WithKeyValue adds key value to the header

type ReaderFunc

type ReaderFunc func(p []byte) (n int, err error)

ReaderFunc proxy implementation

func (ReaderFunc) Read

func (f ReaderFunc) Read(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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