Documentation
¶
Index ¶
- Constants
- Variables
- type Action
- func AssertAll(a ...Action) Action
- func AssertAny(a ...Action) Action
- func AssertBetween[T comparable](min, max T) Action
- func AssertContains(contains string) Action
- func AssertEquals(value any) Action
- func AssertExists() Action
- func AssertGt[T comparable](value T) Action
- func AssertGte[T comparable](value T) Action
- func AssertIn[T any](values ...T) Action
- func AssertJsonPath(path string, action Action) Action
- func AssertKeys(keys ...string) Action
- func AssertKeysIn(keys ...string) Action
- func AssertLen[T constraints.Integer](l T) Action
- func AssertLt[T comparable](value T) Action
- func AssertLte[T comparable](value T) Action
- func AssertNil() Action
- func AssertNot(a Action) Action
- func AssertRegexMatch(pattern *regexp.Regexp) Action
- func AssertRegexSearch(pattern *regexp.Regexp, count int) Action
- func AssertZero() Action
- func Print(target ...io.Writer) Action
- func Unmarshal(into any) Action
- func UnmarshalObjectKeys(keys KV) Action
- type KV
- type Number
- type Support
Constants ¶
const ( // ContextKeyUnmarshalActionValue is a context key for the unmarshal action value. ContextKeyUnmarshalActionValue contextKey = iota )
Variables ¶
var ( // ErrUnmarshal when unmarshalling the response ErrUnmarshal = errors.New("unmarshal error") // ErrActionNotApplied when action is not applied ErrActionNotApplied = errors.New("action not applied") // ErrAction when action is not applied ErrAction = errors.New("action") // ErrNotPresent is passed from tester when value is not present // This is used in some assertions such as AssertExists. ErrNotPresent = errors.New("not present") )
var ( ErrActionAssertBetween = newErrAction("AssertBetween") ErrActionAssertEquals = newErrAction("AssertEquals") ErrActionAssertExists = newErrAction("AssertExists") ErrActionAssertIn = newErrAction("AssertIn") ErrActionAssertKeys = newErrAction("AssertKeys") ErrActionAssertLen = newErrAction("AssertLen") ErrActionAssertGt = newErrAction("AssertGt") ErrActionAssertGte = newErrAction("AssertGte") ErrActionAssertLt = newErrAction("AssertLt") ErrActionAssertLte = newErrAction("AssertLte") ErrActionAssertAll = newErrAction("AssertAll") ErrActionAssertAny = newErrAction("AssertAny") ErrActionAssertRegexMatch = newErrAction("ErrActionAssertRegexMatch") ErrActionAssertRegexSearch = newErrAction("ErrActionAssertRegexSearch") ErrActionUnmarshal = newErrAction("Unmarshal") ErrActionUnmarshalObjectKeys = newErrAction("UnmarshalObjectKeys") ErrActionAssertNot = newErrAction("AssertNot") ErrActionAssertContains = newErrAction("AssertContains") ErrActionAssertNil = newErrAction("AssertNil") ErrActionPath = newErrAction("Path") )
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action interface {
Run(t require.TestingT, ctx context.Context, value any, raw json.RawMessage, err error) error
Value(t require.TestingT) (any, bool)
Supports(support Support) bool
BaseError() error
}
Action is an action that can be performed on the response. It has currently 2 meanings: Assertion and Unmarshal. TODO: add path or id to run so we can print better error messages?
func AssertBetween ¶ added in v0.6.0
func AssertBetween[T comparable](min, max T) Action
AssertBetween asserts that given integer value is between the values (inclusive)
func AssertContains ¶ added in v0.6.0
AssertContains asserts json raw message contains the given string
func AssertEquals ¶
AssertEquals asserts that given value is equal to the value in the response
func AssertExists ¶
func AssertExists() Action
AssertExists asserts that the value exists in the response based on given argument
func AssertGt ¶
func AssertGt[T comparable](value T) Action
AssertGt asserts that given value is greater than the value in the response
func AssertGte ¶
func AssertGte[T comparable](value T) Action
AssertGte asserts that given value is greater than or equal to the value in the response
func AssertJsonPath ¶ added in v0.6.0
AssertJsonPath matches the JSON sub path. This is only used in advanced scenarios.
func AssertKeys ¶
AssertKeys asserts that given map has the given keys
func AssertKeysIn ¶ added in v0.6.0
AssertKeysIn asserts that given map has the given keys
func AssertLen ¶
func AssertLen[T constraints.Integer](l T) Action
AssertLen asserts that given array/object has the given length
func AssertLt ¶
func AssertLt[T comparable](value T) Action
AssertLt asserts that given value is less than the value in the response
func AssertLte ¶
func AssertLte[T comparable](value T) Action
AssertLte asserts that given value is less than or equal to the value in the response
func AssertNot ¶ added in v0.6.0
AssertNot asserts that given action does not succeed, otherwise it fails This assertion does not need any special handling, it just relies on correct errors (ErrAction, ErrNotPresent)
func AssertRegexMatch ¶ added in v0.6.0
AssertRegexMatch asserts that given value matches the regex in the response if count provided it will check for the number of matches, otherwise it will check if the value matches the regex
func AssertRegexSearch ¶ added in v0.6.0
AssertRegexSearch asserts that given regular expression is found given number of times
func AssertZero ¶ added in v0.6.0
func AssertZero() Action
AssertZero asserts that given value is zero value It checks json.RawMessage for zero values
func Print ¶ added in v0.6.0
Print is an action that prints the value and error to the given writer. By default, it prints to os.Stdout.
func UnmarshalObjectKeys ¶
UnmarshalObjectKeys action unmarshal the given json response object keys to the given values kv should be pairs of string key and addressable value
type Number ¶
type Number interface {
constraints.Integer | constraints.Float
}
Number constraint for number types