testutils

package
v0.0.0-...-98cd694 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Unlicense Imports: 24 Imported by: 0

Documentation

Overview

Package testutils contains common functions for integration/load tests

Index

Constants

This section is empty.

Variables

View Source
var ContextMatcher any = mock.MatchedBy(func(context.Context) bool {
	return true
})

ContextMatcher is a matcher for use with testify/mock's MatchBy function. It provides some level of type safety reassurance over mock.Anything, in that the resulting function will panic if anything other than a context.Context.

View Source
var DataChangeMessageMatcher any = mock.MatchedBy(func(*types.DataChangeMessage) bool {
	return true
})

DataChangeMessageMatcher is a matcher for the types.DataChangeMessage interface. It provides some level of type safety reassurance over mock.Anything, in that the resulting function will panic if anything other than a http.ResponseWriter.

View Source
var HTTPRequestMatcher any = mock.MatchedBy(func(*http.Request) bool {
	return true
})

HTTPRequestMatcher is a matcher for use with testify/mock's MatchBy function. It provides some level of type safety reassurance over mock.Anything, in that the resulting function will panic if anything other than a *http.Request.

View Source
var HTTPResponseWriterMatcher any = mock.MatchedBy(func(http.ResponseWriter) bool {
	return true
})

HTTPResponseWriterMatcher is a matcher for the http.ResponseWriter interface. It provides some level of type safety reassurance over mock.Anything, in that the resulting function will panic if anything other than a http.ResponseWriter.

View Source
var QueryFilterMatcher any = mock.MatchedBy(func(*types.QueryFilter) bool {
	return true
})

QueryFilterMatcher is a matcher for use with testify/mock's MatchBy function. It provides some level of type safety reassurance over mock.Anything, in that the resulting function will panic if anything other than a context.Context.

Functions

func BrokenSessionContextDataFetcher

func BrokenSessionContextDataFetcher(*http.Request) (*types.SessionContextData, error)

BrokenSessionContextDataFetcher is a deliberately broken sessionContextDataFetcher.

func BuildArbitraryImage

func BuildArbitraryImage(widthAndHeight int) image.Image

BuildArbitraryImage builds an image with a bunch of colors in it.

func BuildArbitraryImagePNGBytes

func BuildArbitraryImagePNGBytes(widthAndHeight int) (img image.Image, imgBytes []byte)

BuildArbitraryImagePNGBytes builds an image with a bunch of colors in it.

func BuildTestRequest

func BuildTestRequest(t *testing.T) *http.Request

BuildTestRequest builds an arbitrary *http.Request.

func CreateServiceUser

func CreateServiceUser(ctx context.Context, address string, in *types.UserRegistrationInput) (*types.User, error)

CreateServiceUser creates a user.

func GetLoginCookie

func GetLoginCookie(ctx context.Context, serviceURL string, u *types.User) (*http.Cookie, error)

GetLoginCookie fetches a login cookie for a given user.

Types

type MockHTTPHandler

type MockHTTPHandler struct {
	mock.Mock
}

MockHTTPHandler is a mocked http.Handler.

func (*MockHTTPHandler) ServeHTTP

func (m *MockHTTPHandler) ServeHTTP(res http.ResponseWriter, req *http.Request)

ServeHTTP satisfies our interface requirements.

type MockHTTPResponseWriter

type MockHTTPResponseWriter struct {
	mock.Mock
}

MockHTTPResponseWriter is a mock http.ResponseWriter.

func (*MockHTTPResponseWriter) Header

func (m *MockHTTPResponseWriter) Header() http.Header

Header satisfies our interface requirements.

func (*MockHTTPResponseWriter) Write

func (m *MockHTTPResponseWriter) Write(in []byte) (int, error)

Write satisfies our interface requirements.

func (*MockHTTPResponseWriter) WriteHeader

func (m *MockHTTPResponseWriter) WriteHeader(statusCode int)

WriteHeader satisfies our interface requirements.

type MockReadCloser

type MockReadCloser struct {
	mock.Mock
}

MockReadCloser mocks a io.ReadCloser.

func (*MockReadCloser) Close

func (m *MockReadCloser) Close() (err error)

Close implements the io.ReadCloser interface.

func (*MockReadCloser) Read

func (m *MockReadCloser) Read(p []byte) (n int, err error)

Read implements the io.ReadCloser interface.

Jump to

Keyboard shortcuts

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