check

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingCheckFunc is returned when a BodyCustomChecker is checked without a valid func.
	ErrMissingCheckFunc = errors.New("missing check func")
)

Functions

func ContextWithData

func ContextWithData(ctx context.Context, data map[string]interface{}) context.Context

ContextWithData embeds the given data in the context.

func ContextWithDataID

func ContextWithDataID(ctx context.Context, id string, val interface{}) error

ContextWithDataID embeds the given data item in the context.

func ContextWithOptionalDataID

func ContextWithOptionalDataID(ctx context.Context, id string, val interface{}) error

ContextWithDataID embeds the given data item in the context, if the ID is not empty.

func DataFromContext

func DataFromContext(ctx context.Context) map[string]interface{}

DataFromContext returns a map of check data from the context.

func DataIDFromContext

func DataIDFromContext(ctx context.Context, id string) interface{}

DataIDFromContext returns data with the given ID from the context.

Types

type BodyCustomChecker

type BodyCustomChecker struct {
	CheckBody BodyCustomCheckerFunc
}

BodyCustomChecker is used to run a BodyCustomCheckerFunc against the body bytes in the http response

func (*BodyCustomChecker) Check

func (c *BodyCustomChecker) Check(ctx context.Context, response *http.Response) error

Check performs the BodyCustom check

type BodyCustomCheckerFunc

type BodyCustomCheckerFunc func([]byte) error

BodyCustomCheckerFunc defines the function used to perform a custom http response body check

type BodyEqualChecker

type BodyEqualChecker struct {
	Value string
}

BodyEqualChecker is used to validate the http response body string exactly matches `Value`

func (*BodyEqualChecker) Check

func (c *BodyEqualChecker) Check(ctx context.Context, response *http.Response) error

Check performs the BodyEqual check

type BodyJSONChecker

type BodyJSONChecker struct {
	Value interface{}
}

BodyJSONChecker is used to validate http response body can be JSON decoded and is equal to `Value`

func (*BodyJSONChecker) Check

func (c *BodyJSONChecker) Check(ctx context.Context, response *http.Response) error

Check performs the BodyJSON check

type BodyJSONQueryEqualChecker

type BodyJSONQueryEqualChecker struct {
	Query     string
	Value     interface{}
	NullValue bool
	DataID    string
}

BodyJSONQueryEqualChecker queries the http response body JSON using `Query` and ensures the value is equal to `Value`

func (*BodyJSONQueryEqualChecker) Check

func (c *BodyJSONQueryEqualChecker) Check(ctx context.Context, response *http.Response) error

Check performs the BodyJSONQueryEqual check

type BodyJSONQueryExistsChecker

type BodyJSONQueryExistsChecker struct {
	Query  string
	DataID string
}

BodyJSONQueryExistsChecker queries the http response body JSON using `Query` and ensures a value exists there

func (*BodyJSONQueryExistsChecker) Check

func (c *BodyJSONQueryExistsChecker) Check(ctx context.Context, response *http.Response) error

Check performs the BodyJSONQueryExists check

type BodyJSONQueryRegexMatchChecker

type BodyJSONQueryRegexMatchChecker struct {
	Query   string
	Regexp  *regexp.Regexp
	DataIDs map[int]string
}

BodyJSONQueryRegexMatchChecker queries the http response body JSON using `Query` and ensures that it matches the regex pattern in `Regexp`

func (*BodyJSONQueryRegexMatchChecker) Check

Check performs the BodyJSONQueryRegexMatch check

type Checker

type Checker interface {
	Check(ctx context.Context, response *http.Response) error
}

Checker is used to outline each individual response check

type DataEqualChecker

type DataEqualChecker struct {
	DataID string
	Value  interface{}
}

DataEqualChecker is used to check whether or not the value stored in the context data is equal to the given value

func (*DataEqualChecker) Check

func (c *DataEqualChecker) Check(ctx context.Context, response *http.Response) error

Check performs the DataEqual check

type JSONQueryValueMissingError

type JSONQueryValueMissingError struct {
	// Query is the JSON query.
	Query string
}

JSONQueryValueMissingError is returned when a check fails.

func (*JSONQueryValueMissingError) Error

Error returns an error string.

type StatusCodeEqualChecker

type StatusCodeEqualChecker struct {
	Value int
}

StatusCodeEqualChecker is used to validate the status code in the response

func (*StatusCodeEqualChecker) Check

func (c *StatusCodeEqualChecker) Check(ctx context.Context, response *http.Response) error

Check performs the StatusCodeEqual check

type UnexpectedDataValueError

type UnexpectedDataValueError struct {
	// DataID is the ID of the data.
	DataID string
	// Expected is the expected value.
	Expected interface{}
	// Actual is the actual value.
	Actual interface{}
}

UnexpectedDataValueError is returned when a check fails.

func (*UnexpectedDataValueError) Error

func (e *UnexpectedDataValueError) Error() string

Error returns an error string.

type UnexpectedJSONBodyError

type UnexpectedJSONBodyError struct {
	// Expected is the expected value.
	Expected interface{}
	// Actual is the actual value.
	Actual interface{}
}

UnexpectedJSONBodyError is returned when a check fails.

func (*UnexpectedJSONBodyError) Error

func (e *UnexpectedJSONBodyError) Error() string

Error returns an error string.

type UnexpectedJSONQueryRegexValueError

type UnexpectedJSONQueryRegexValueError struct {
	// Pattern is the regex pattern.
	Pattern string
	// Query is the JSON query.
	Query string
	// Actual is the actual value.
	Actual string
}

UnexpectedJSONQueryRegexValueError is returned when a check fails.

func (*UnexpectedJSONQueryRegexValueError) Error

Error returns an error string.

type UnexpectedJSONQueryValueError

type UnexpectedJSONQueryValueError struct {
	// Query is the JSON query.
	Query string
	// Expected is the expected value.
	Expected interface{}
	// Actual is the actual value.
	Actual interface{}
}

UnexpectedJSONQueryValueError is returned when a check fails.

func (*UnexpectedJSONQueryValueError) Error

Error returns an error string.

type UnexpectedStatusCode

type UnexpectedStatusCode struct {
	// Expected is the expected status code.
	Expected int
	// Actual is the actual status code.
	Actual int
}

UnexpectedStatusCode is returned when a check fails.

func (*UnexpectedStatusCode) Error

func (e *UnexpectedStatusCode) Error() string

Error returns an error string.

type UnexpectedValueError

type UnexpectedValueError struct {
	// Expected is the expected value.
	Expected string
	// Actual is the actual value.
	Actual string
}

UnexpectedValueError is returned when a check fails.

func (*UnexpectedValueError) Error

func (e *UnexpectedValueError) Error() string

Error returns an error string.

Jump to

Keyboard shortcuts

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