testutils

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2022 License: Unlicense Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorVerifier

func ErrorVerifier(env string, pkg string, file string, class string,
	function string, line int, innerVerifier func(error), message string,
	msgParts ...string) func(*utils.GError)

ErrorVerifier verifies the fields on a backend Error

func GenerateResponse

func GenerateResponse(request *http.Request, code int, item string) *http.Response

GenerateResponse creates an HTTP response we can use in our testing

func InnerErrorPrefixSuffixVerifier

func InnerErrorPrefixSuffixVerifier(prefix string, suffix string) func(error)

InnerErrorPrefixSuffixVerifier verifies that an error message has a given prefix and suffix

func InnerErrorVerifier

func InnerErrorVerifier(message string) func(error)

InnerErrorVerifier verifies an error message

func ItemIsNil

func ItemIsNil[T any](item T)

ItemIsNil is a function that verifies that the data sent to it is nil

func NewTestClient

func NewTestClient(shouldFail bool, fns ...func(*http.Request) *http.Response) *http.Client

NewTestClient returns an HTTP client with the transport replaced to avoid make real HTTP requests against the endpionts sent to it

func NoInnerError

func NoInnerError() func(error)

NoInnerError verifies that an error did not occur

func VerifyAndGenerateResponse

func VerifyAndGenerateResponse(method string, uri string, code int,
	data string) func(*http.Request) *http.Response

VerifyAndGenerateResponse verifies the HTTP request and generates an HTTP response

func VerifyRequest

func VerifyRequest(req *http.Request, method string, uri string)

VerifyRequest verifies the details of an HTTP request

Types

type ErrorReader

type ErrorReader int

ErrorReader is a mock type we'll use in place of a reader so we can test out errors when Read is called

func (ErrorReader) Read

func (ErrorReader) Read([]byte) (int, error)

Read allows for the Reader interface to be implemented and returns an error

type RoundTripFunc

type RoundTripFunc struct {
	Functions  []func(*http.Request) *http.Response
	Index      int
	ShouldFail bool
}

RoundTripFunc allows us to encapsulate the functionality necessary to mock HTTP requests made from an HTTP client so we can test our request functions

func (*RoundTripFunc) RoundTrip

func (f *RoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip runs a single HTTP request

type StringMatch

type StringMatch struct {
	Prefix   string
	Suffix   string
	Contains []string
}

StringMatch allows for matching a string argument based on a prefix and suffix

func NewStringMatch

func NewStringMatch(prefix string, suffix string, contains ...string) StringMatch

NewStringMatch creates a new string match from the expected prefix, suffix and any values that should be contained in the string

func (StringMatch) Match

func (match StringMatch) Match(v driver.Value) bool

Match checks that an SQL value matches the string provided

Jump to

Keyboard shortcuts

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