action

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContextKeyUnmarshalActionValue is a context key for the unmarshal action value.
	ContextKeyUnmarshalActionValue contextKey = iota
)

Variables

View Source
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")
)
View Source
var (
	ErrActionAssertEquals        = newErrAction("AssertEquals")
	ErrActionAssertExists        = newErrAction("AssertExists")
	ErrActionAssertIn            = newErrAction("AssertIn")
	ErrActionAssertKeys          = newErrAction("AssertKeys")
	ErrActionAssertLen           = newErrAction("AssertLen")
	ErrActionAssertNotEquals     = newErrAction("AssertNotEquals")
	ErrActionAssertNotExists     = newErrAction("AssertNotExists")
	ErrActionAssertNotIn         = newErrAction("AssertNotIn")
	ErrActionAssertGt            = newErrAction("AssertGt")
	ErrActionAssertGte           = newErrAction("AssertGte")
	ErrActionAssertLt            = newErrAction("AssertLt")
	ErrActionAssertLte           = newErrAction("AssertLte")
	ErrActionAssertAll           = newErrAction("AssertAll")
	ErrActionAssertAny           = newErrAction("AssertAny")
	ErrActionAssertRegex         = newErrAction("AssertRegex")
	ErrActionUnmarshal           = newErrAction("Unmarshal")
	ErrActionUnmarshalObjectKeys = newErrAction("UnmarshalObjectKeys")
)

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 AssertAll

func AssertAll(a ...Action) Action

AssertAll asserts that all actions are executed

func AssertAny

func AssertAny(a ...Action) Action

AssertAny asserts that any action succeeded

func AssertEquals

func AssertEquals(value any) Action

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 constraints.Integer](value T) Action

AssertGt asserts that given value is greater than the value in the response

func AssertGte

func AssertGte[T constraints.Integer](value T) Action

AssertGte asserts that given value is greater than or equal to the value in the response

func AssertIn

func AssertIn[T any](values ...T) Action

AssertIn asserts that value is in the given list of values

func AssertKeys

func AssertKeys(keys ...string) Action

AssertKeys 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 constraints.Integer](value T) Action

AssertLt asserts that given value is less than the value in the response

func AssertLte

func AssertLte[T constraints.Integer](value T) Action

AssertLte asserts that given value is less than or equal to the value in the response

func AssertNotEquals

func AssertNotEquals(value any) Action

AssertNotEquals asserts that given value is not equal to the value in the response

func AssertNotExists

func AssertNotExists() Action

AssertNotExists asserts that the value does not exist in the response based on given argument

func AssertNotIn

func AssertNotIn[T any](values ...T) Action

AssertNotIn asserts that value is not in the given list of values

func AssertRegex

func AssertRegex(pattern *regexp.Regexp, count ...int) Action

AssertRegex 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 Unmarshal

func Unmarshal(into any) Action

Unmarshal action unmarshal the given json response to the given value

func UnmarshalObjectKeys

func UnmarshalObjectKeys(keys KV) Action

UnmarshalObjectKeys action unmarshal the given json response object keys to the given values kv should be pairs of string key and addressable value

type KV

type KV map[string]any

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

Number constraint for number types

type Support

type Support int
const (
	SupportHeader Support = iota
	SupportJson
	SupportStatus
)

Jump to

Keyboard shortcuts

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