Documentation
¶
Overview ¶
Package testastic provides JSON assertion utilities for Go tests. It compares API responses against expected JSON files with support for template-based matchers, semantic comparison, and automatic updates.
Index ¶
- Variables
- func AssertFile[T any](tb testing.TB, expectedFile string, actual T, opts ...AssertionOption)
- func AssertHTML[T any](tb testing.TB, expectedFile string, actual T, opts ...AssertionOption)
- func AssertJSON[T any](tb testing.TB, expectedFile string, actual T, opts ...AssertionOption)
- func AssertYAML[T any](tb testing.TB, expectedFile string, actual T, opts ...AssertionOption)
- func Between[T cmp.Ordered](tb testing.TB, value, minVal, maxVal T)
- func Contains(tb testing.TB, s, substring string)
- func DeepEqual[T any](tb testing.TB, expected, actual T)
- func Empty(tb testing.TB, collection any)
- func Equal[T comparable](tb testing.TB, expected, actual T)
- func Error(tb testing.TB, err error)
- func ErrorContains(tb testing.TB, err error, substring string)
- func ErrorIs(tb testing.TB, err, target error)
- func Eventually(tb testing.TB, condition func() bool, timeout time.Duration, ...)
- func EventuallyEqual[T comparable](tb testing.TB, expected T, getValue func() T, timeout time.Duration, ...)
- func EventuallyError(tb testing.TB, getErr func() error, timeout time.Duration, ...)
- func EventuallyFalse(tb testing.TB, condition func() bool, timeout time.Duration, ...)
- func EventuallyNil(tb testing.TB, getValue func() any, timeout time.Duration, ...)
- func EventuallyNoError(tb testing.TB, getErr func() error, timeout time.Duration, ...)
- func EventuallyNotNil(tb testing.TB, getValue func() any, timeout time.Duration, ...)
- func EventuallyTrue(tb testing.TB, condition func() bool, timeout time.Duration, ...)
- func False(tb testing.TB, value bool)
- func FormatFileDiffInline(expected, actual []string) string
- func FormatHTMLDiff(diffs []HTMLDifference) string
- func FormatHTMLDiffInline(expected, actual *HTMLNode) string
- func FormatJSONDiff(diffs []Difference) string
- func FormatJSONDiffInline(expected, actual any) string
- func FormatYAMLDiff(diffs []Difference) string
- func FormatYAMLDiffInline(expected, actual any) string
- func Greater[T cmp.Ordered](tb testing.TB, a, b T)
- func GreaterOrEqual[T cmp.Ordered](tb testing.TB, a, b T)
- func HasPrefix(tb testing.TB, s, prefix string)
- func HasSuffix(tb testing.TB, s, suffix string)
- func IsIgnore(m Matcher) bool
- func Len(tb testing.TB, collection any, expected int)
- func Less[T cmp.Ordered](tb testing.TB, a, b T)
- func LessOrEqual[T cmp.Ordered](tb testing.TB, a, b T)
- func MapEqual[K comparable, V comparable](tb testing.TB, expected, actual map[K]V)
- func MapHasKey[K comparable, V any](tb testing.TB, m map[K]V, key K)
- func MapNotHasKey[K comparable, V any](tb testing.TB, m map[K]V, key K)
- func Matches(tb testing.TB, s, pattern string)
- func Nil(tb testing.TB, value any)
- func NoError(tb testing.TB, err error)
- func NotContains(tb testing.TB, s, substring string)
- func NotEmpty(tb testing.TB, collection any)
- func NotEqual[T comparable](tb testing.TB, unexpected, actual T)
- func NotNil(tb testing.TB, value any)
- func RegisterMatcher(name string, factory MatcherFactory)
- func SliceContains[T comparable](tb testing.TB, slice []T, element T)
- func SliceEqual[T comparable](tb testing.TB, expected, actual []T)
- func SliceNotContains[T comparable](tb testing.TB, slice []T, element T)
- func StringEmpty(tb testing.TB, s string)
- func StringNotEmpty(tb testing.TB, s string)
- func True(tb testing.TB, value bool)
- type AssertionOption
- func IgnoreArrayOrder() AssertionOption
- func IgnoreArrayOrderAt(path string) AssertionOption
- func IgnoreFields(fields ...string) AssertionOption
- func Message(msg string) AssertionOption
- func Update() AssertionOption
- func WrapHTMLOption(opt HTMLOption) AssertionOption
- func WrapJSONOption(opt JSONOption) AssertionOption
- func WrapYAMLOption(opt YAMLOption) AssertionOption
- type BaseConfig
- type CompareConfig
- type DiffType
- type Difference
- type EventuallyOption
- type ExpectedHTML
- type ExpectedJSON
- type ExpectedYAML
- type FileConfig
- type FileOption
- type HTMLConfig
- type HTMLDifference
- type HTMLNode
- type HTMLNodeType
- type HTMLOption
- func ConvertToHTMLOption(opt AssertionOption) HTMLOption
- func HTMLMessage(msg string) HTMLOption
- func HTMLUpdate() HTMLOption
- func IgnoreAttributeAt(pathAttr string) HTMLOption
- func IgnoreAttributes(attrs ...string) HTMLOption
- func IgnoreChildOrder() HTMLOption
- func IgnoreChildOrderAt(path string) HTMLOption
- func IgnoreElements(tags ...string) HTMLOption
- func IgnoreHTMLComments() HTMLOption
- func PreserveWhitespace() HTMLOption
- type JSONConfig
- type JSONOption
- type Matcher
- func AnyBool() Matcher
- func AnyDateTime() Matcher
- func AnyFloat() Matcher
- func AnyInt() Matcher
- func AnyString() Matcher
- func AnyURL() Matcher
- func AnyUUID() Matcher
- func AnyValue() Matcher
- func Ignore() Matcher
- func OneOf(values ...any) Matcher
- func ParseMatcher(expr string) (Matcher, error)
- func Regex(pattern string) (Matcher, error)
- type MatcherFactory
- type TemplateSegment
- type TemplateString
- type YAMLConfig
- type YAMLOption
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidRegexSyntax = errors.New("invalid regex syntax") ErrInvalidOneOfSyntax = errors.New("invalid oneOf syntax") ErrUnknownMatcher = errors.New("unknown matcher") )
Matcher parsing errors.
var ErrUnknownPlaceholder = errors.New("unknown placeholder")
ErrUnknownPlaceholder is returned when a placeholder is not found in the matcher map.
var ErrUnsupportedFileType = errors.New("unsupported type, expected string, []byte, or io.Reader")
ErrUnsupportedFileType is returned when an unsupported type is passed to AssertFile.
var ErrUnsupportedHTMLType = errors.New("unsupported type for HTML comparison")
ErrUnsupportedHTMLType is returned when an unsupported type is passed to AssertHTML.
Functions ¶
func AssertFile ¶
func AssertFile[T any](tb testing.TB, expectedFile string, actual T, opts ...AssertionOption)
AssertFile compares actual content against an expected file with template matcher support. Supports {{anyString}}, {{regex `pattern`}}, and other matchers inline within text.
Supported actual types: string, []byte, or io.Reader.
func AssertHTML ¶
func AssertHTML[T any](tb testing.TB, expectedFile string, actual T, opts ...AssertionOption)
AssertHTML compares actual HTML against an expected HTML file. T can be: []byte, string, io.Reader, or any type implementing fmt.Stringer.
Example:
testastic.AssertHTML(t, "testdata/user.expected.html", resp.Body) testastic.AssertHTML(t, "testdata/user.expected.html", htmlBytes) testastic.AssertHTML(t, "testdata/user.expected.html", htmlString)
func AssertJSON ¶
func AssertJSON[T any](tb testing.TB, expectedFile string, actual T, opts ...AssertionOption)
AssertJSON compares actual JSON against an expected JSON file. T can be: []byte, string, io.Reader, or any struct (auto-marshaled).
Example:
testastic.AssertJSON(t, "testdata/user.expected.json", resp.Body) testastic.AssertJSON(t, "testdata/user.expected.json", myUser) testastic.AssertJSON(t, "testdata/user.expected.json", jsonBytes)
func AssertYAML ¶
func AssertYAML[T any](tb testing.TB, expectedFile string, actual T, opts ...AssertionOption)
AssertYAML compares actual YAML against an expected YAML file. T can be: []byte, string, io.Reader, or any struct (auto-marshaled).
Example:
testastic.AssertYAML(t, "testdata/config.expected.yaml", configBytes) testastic.AssertYAML(t, "testdata/config.expected.yaml", myConfig) testastic.AssertYAML(t, "testdata/config.expected.yaml", resp.Body)
func DeepEqual ¶
DeepEqual asserts that expected and actual are deeply equal using reflect.DeepEqual.
func Empty ¶
Empty asserts that the collection is empty. Works with slices, maps, strings, arrays, and channels.
func Equal ¶
func Equal[T comparable](tb testing.TB, expected, actual T)
Equal asserts that expected and actual are equal.
func ErrorContains ¶
ErrorContains asserts that err contains the given substring.
func Eventually ¶
func Eventually(tb testing.TB, condition func() bool, timeout time.Duration, opts ...EventuallyOption)
Eventually retries a condition function until it returns true or timeout is reached. The condition is checked immediately, then at regular intervals (default 100ms).
Example:
testastic.Eventually(t, func() bool {
return server.IsReady()
}, 5*time.Second)
testastic.Eventually(t, func() bool {
return len(queue) > 0
}, 2*time.Second, testastic.WithInterval(50*time.Millisecond))
func EventuallyEqual ¶
func EventuallyEqual[T comparable]( tb testing.TB, expected T, getValue func() T, timeout time.Duration, opts ...EventuallyOption, )
EventuallyEqual retries until expected equals the result of getValue.
Example:
testastic.EventuallyEqual(t, "ready", func() string {
return service.Status()
}, 3*time.Second)
func EventuallyError ¶
func EventuallyError(tb testing.TB, getErr func() error, timeout time.Duration, opts ...EventuallyOption)
EventuallyError retries until getErr returns a non-nil error.
Example:
testastic.EventuallyError(t, func() error {
return service.HealthCheck()
}, 3*time.Second)
func EventuallyFalse ¶
func EventuallyFalse(tb testing.TB, condition func() bool, timeout time.Duration, opts ...EventuallyOption)
EventuallyFalse retries until condition returns false.
Example:
testastic.EventuallyFalse(t, func() bool {
return server.IsProcessing()
}, 5*time.Second)
func EventuallyNil ¶
func EventuallyNil(tb testing.TB, getValue func() any, timeout time.Duration, opts ...EventuallyOption)
EventuallyNil retries until getValue returns nil.
Example:
testastic.EventuallyNil(t, func() any {
return cache.Get("key")
}, 2*time.Second)
func EventuallyNoError ¶
func EventuallyNoError(tb testing.TB, getErr func() error, timeout time.Duration, opts ...EventuallyOption)
EventuallyNoError retries until getErr returns nil.
Example:
testastic.EventuallyNoError(t, func() error {
_, err := client.Ping()
return err
}, 5*time.Second)
func EventuallyNotNil ¶
func EventuallyNotNil(tb testing.TB, getValue func() any, timeout time.Duration, opts ...EventuallyOption)
EventuallyNotNil retries until getValue returns a non-nil value.
Example:
testastic.EventuallyNotNil(t, func() any {
return cache.Get("key")
}, 2*time.Second)
func EventuallyTrue ¶
func EventuallyTrue(tb testing.TB, condition func() bool, timeout time.Duration, opts ...EventuallyOption)
EventuallyTrue is an alias for Eventually for readability.
Example:
testastic.EventuallyTrue(t, func() bool {
return isReady
}, 3*time.Second)
func FormatFileDiffInline ¶
FormatFileDiffInline generates a git-style inline diff for file comparison.
func FormatHTMLDiff ¶
func FormatHTMLDiff(diffs []HTMLDifference) string
func FormatHTMLDiffInline ¶
FormatHTMLDiffInline generates a git-style inline diff between expected and actual HTML. Uses the same format as JSON diff.
func FormatJSONDiff ¶
func FormatJSONDiff(diffs []Difference) string
FormatJSONDiff formats a slice of differences into a human-readable string. This is the simple format showing paths and values.
func FormatJSONDiffInline ¶
FormatJSONDiffInline generates a git-style inline diff between expected and actual JSON. Shows the full JSON with - prefix for removed lines and + prefix for added lines.
func FormatYAMLDiff ¶
func FormatYAMLDiff(diffs []Difference) string
func FormatYAMLDiffInline ¶
FormatYAMLDiffInline generates a git-style inline diff between expected and actual YAML.
func GreaterOrEqual ¶
GreaterOrEqual asserts that a >= b.
func Len ¶
Len asserts that the collection has the expected length. Works with slices, maps, strings, arrays, and channels.
func LessOrEqual ¶
LessOrEqual asserts that a <= b.
func MapEqual ¶
func MapEqual[K comparable, V comparable](tb testing.TB, expected, actual map[K]V)
MapEqual asserts that two maps are equal.
func MapHasKey ¶
func MapHasKey[K comparable, V any](tb testing.TB, m map[K]V, key K)
MapHasKey asserts that the map contains the given key.
func MapNotHasKey ¶
func MapNotHasKey[K comparable, V any](tb testing.TB, m map[K]V, key K)
MapNotHasKey asserts that the map does not contain the given key.
func NotContains ¶
NotContains asserts that s does not contain substring.
func NotEmpty ¶
NotEmpty asserts that the collection is not empty. Works with slices, maps, strings, arrays, and channels.
func NotEqual ¶
func NotEqual[T comparable](tb testing.TB, unexpected, actual T)
NotEqual asserts that expected and actual are not equal.
func RegisterMatcher ¶
func RegisterMatcher(name string, factory MatcherFactory)
RegisterMatcher registers a custom matcher factory with the given name.
func SliceContains ¶
func SliceContains[T comparable](tb testing.TB, slice []T, element T)
SliceContains asserts that slice contains element.
func SliceEqual ¶
func SliceEqual[T comparable](tb testing.TB, expected, actual []T)
SliceEqual asserts that two slices are equal (same length and elements in same order).
func SliceNotContains ¶
func SliceNotContains[T comparable](tb testing.TB, slice []T, element T)
SliceNotContains asserts that slice does not contain element.
func StringEmpty ¶
StringEmpty asserts that s is an empty string.
func StringNotEmpty ¶
StringNotEmpty asserts that s is not an empty string.
Types ¶
type AssertionOption ¶
type AssertionOption interface {
// contains filtered or unexported methods
}
AssertionOption is a common interface for all assertion options.
func IgnoreArrayOrder ¶
func IgnoreArrayOrder() AssertionOption
IgnoreArrayOrder makes array comparison order-insensitive globally.
func IgnoreArrayOrderAt ¶
func IgnoreArrayOrderAt(path string) AssertionOption
IgnoreArrayOrderAt makes array comparison order-insensitive at the specified path.
func IgnoreFields ¶
func IgnoreFields(fields ...string) AssertionOption
IgnoreFields excludes the specified fields from comparison.
func Message ¶
func Message(msg string) AssertionOption
Message adds a custom message to the assertion failure output.
func Update ¶
func Update() AssertionOption
Update forces updating the expected file with the actual value.
func WrapHTMLOption ¶
func WrapHTMLOption(opt HTMLOption) AssertionOption
WrapHTMLOption wraps an HTMLOption to implement AssertionOption.
func WrapJSONOption ¶
func WrapJSONOption(opt JSONOption) AssertionOption
WrapJSONOption wraps an Option to implement AssertionOption.
func WrapYAMLOption ¶
func WrapYAMLOption(opt YAMLOption) AssertionOption
WrapYAMLOption wraps a YAMLOption to implement AssertionOption.
type BaseConfig ¶
type BaseConfig struct {
IgnoreArrayOrder bool
IgnoreArrayOrderPaths []string
IgnoredFields []string
Update bool
Message string
}
BaseConfig holds common configuration shared across all assertion types.
func (*BaseConfig) IsFieldIgnored ¶
func (c *BaseConfig) IsFieldIgnored(path string) bool
IsFieldIgnored checks if a field at the given path should be ignored. Fields can be matched by exact path (e.g., "$.user.id") or by field name only (e.g., "id"). When matching by field name, all fields with that name at any depth are ignored.
func (*BaseConfig) ShouldIgnoreArrayOrder ¶
func (c *BaseConfig) ShouldIgnoreArrayOrder(path string) bool
ShouldIgnoreArrayOrder checks if array order should be ignored at the given path.
type CompareConfig ¶
type CompareConfig interface {
ShouldIgnoreArrayOrder(path string) bool
IsFieldIgnored(path string) bool
}
CompareConfig is the interface for comparison configuration.
type DiffType ¶
type DiffType int
DiffType represents the type of difference found.
const ( // DiffChanged indicates a value was modified. DiffChanged DiffType = iota // DiffAdded indicates a value was added (exists in actual but not expected). DiffAdded // DiffRemoved indicates a value was removed (exists in expected but not actual). DiffRemoved // DiffTypeMismatch indicates the types don't match. DiffTypeMismatch // DiffMatcherFailed indicates a matcher didn't match the actual value. DiffMatcherFailed )
type Difference ¶
type Difference struct {
Path string // JSON path, e.g., "$.users[0].name"
Expected any // Expected value (or matcher description)
Actual any // Actual value
Type DiffType // Type of difference
}
Difference represents a single difference between expected and actual JSON.
type EventuallyOption ¶
type EventuallyOption func(*eventuallyConfig)
EventuallyOption configures Eventually behavior.
func WithInterval ¶
func WithInterval(d time.Duration) EventuallyOption
WithInterval sets the polling interval between condition checks. Default is 100ms.
func WithMessage ¶
func WithMessage(msg string) EventuallyOption
WithMessage adds context to failure messages.
type ExpectedHTML ¶
ExpectedHTML represents a parsed expected HTML file with matchers.
func ParseExpectedHTMLFile ¶
func ParseExpectedHTMLFile(path string) (*ExpectedHTML, error)
ParseExpectedHTMLFile reads and parses an expected HTML file, replacing template expressions with matchers.
func ParseExpectedHTMLString ¶
func ParseExpectedHTMLString(content string) (*ExpectedHTML, error)
ParseExpectedHTMLString parses an expected HTML string with template expressions.
func (*ExpectedHTML) ExtractMatcherPositions ¶
func (e *ExpectedHTML) ExtractMatcherPositions() map[string]string
ExtractMatcherPositions returns a map of HTML paths to their original template expressions.
type ExpectedJSON ¶
type ExpectedJSON struct {
Data any // Parsed JSON with Matcher objects in place of template expressions
Matchers map[string]string // Map of placeholder to original template expression
Raw string // Original file content for update operations
}
ExpectedJSON represents a parsed expected file with matchers.
func ParseExpectedJSONFile ¶
func ParseExpectedJSONFile(path string) (*ExpectedJSON, error)
ParseExpectedJSONFile reads and parses an expected file, replacing template expressions with matchers.
func ParseExpectedJSONString ¶
func ParseExpectedJSONString(content string) (*ExpectedJSON, error)
ParseExpectedJSONString parses an expected JSON string with template expressions.
func (*ExpectedJSON) ExtractMatcherPositions ¶
func (e *ExpectedJSON) ExtractMatcherPositions() map[string]string
ExtractMatcherPositions returns a map of JSON paths to their original template expressions. This is used when updating expected files to preserve matchers.
type ExpectedYAML ¶
type ExpectedYAML struct {
Data any // Parsed YAML with Matcher objects in place of template expressions
Matchers map[string]string // Map of placeholder to original template expression
Raw string // Original file content for update operations
}
ExpectedYAML represents a parsed expected YAML file with matchers.
func ParseExpectedYAMLFile ¶
func ParseExpectedYAMLFile(path string) (*ExpectedYAML, error)
ParseExpectedYAMLFile reads and parses an expected YAML file, replacing template expressions with matchers.
func ParseExpectedYAMLString ¶
func ParseExpectedYAMLString(content string) (*ExpectedYAML, error)
ParseExpectedYAMLString parses an expected YAML string with template expressions.
func (*ExpectedYAML) ExtractMatcherPositions ¶
func (e *ExpectedYAML) ExtractMatcherPositions() map[string]string
ExtractMatcherPositions returns a map of YAML paths to their original template expressions.
type FileConfig ¶
type FileConfig struct {
BaseConfig
}
FileConfig holds configuration for file assertions.
type FileOption ¶
type FileOption func(*FileConfig)
FileOption is a functional option for configuring file comparison.
type HTMLConfig ¶
type HTMLConfig struct {
BaseConfig
IgnoreComments bool
PreserveWhitespace bool
IgnoredElements []string
IgnoredAttributes []string
IgnoredAttributePaths []string
}
HTMLConfig holds the configuration for HTML comparison.
func (*HTMLConfig) IsFieldIgnored ¶
func (c *HTMLConfig) IsFieldIgnored(path string) bool
IsFieldIgnored checks if an element should be ignored.
type HTMLDifference ¶
HTMLDifference represents a single difference between expected and actual HTML.
type HTMLNode ¶
type HTMLNode struct {
Type HTMLNodeType
Tag string
Attributes map[string]any
Children []*HTMLNode
Text any
Path string
}
HTMLNode represents a normalized HTML node for comparison.
type HTMLNodeType ¶
type HTMLNodeType int
HTMLNodeType represents the type of an HTML node.
const ( // HTMLElement represents an HTML element node. HTMLElement HTMLNodeType = iota // HTMLText represents a text node. HTMLText // HTMLComment represents a comment node. HTMLComment // HTMLDoctype represents a doctype node. HTMLDoctype )
type HTMLOption ¶
type HTMLOption func(*HTMLConfig)
HTMLOption is a functional option for configuring HTML comparison.
func ConvertToHTMLOption ¶
func ConvertToHTMLOption(opt AssertionOption) HTMLOption
ConvertToHTMLOption converts an AssertionOption to an HTMLOption.
func HTMLMessage ¶
func HTMLMessage(msg string) HTMLOption
HTMLMessage adds a custom message to the assertion failure output.
func HTMLUpdate ¶
func HTMLUpdate() HTMLOption
HTMLUpdate forces updating the expected file with the actual value.
func IgnoreAttributeAt ¶
func IgnoreAttributeAt(pathAttr string) HTMLOption
IgnoreAttributeAt excludes a specific attribute at a given path.
func IgnoreAttributes ¶
func IgnoreAttributes(attrs ...string) HTMLOption
IgnoreAttributes excludes the specified attribute names from comparison globally.
func IgnoreChildOrder ¶
func IgnoreChildOrder() HTMLOption
IgnoreChildOrder makes child element comparison order-insensitive globally.
func IgnoreChildOrderAt ¶
func IgnoreChildOrderAt(path string) HTMLOption
IgnoreChildOrderAt makes child comparison order-insensitive at the specified HTML path.
func IgnoreElements ¶
func IgnoreElements(tags ...string) HTMLOption
IgnoreElements excludes elements matching the specified tag names from comparison.
func IgnoreHTMLComments ¶
func IgnoreHTMLComments() HTMLOption
IgnoreHTMLComments excludes HTML comments from comparison.
func PreserveWhitespace ¶
func PreserveWhitespace() HTMLOption
PreserveWhitespace disables whitespace normalization.
type JSONConfig ¶
type JSONConfig struct {
BaseConfig
}
JSONConfig holds the configuration for JSON comparison.
type JSONOption ¶
type JSONOption func(*JSONConfig)
JSONOption is a functional option for configuring JSON comparison.
func ConvertToJSONOption ¶
func ConvertToJSONOption(opt AssertionOption) JSONOption
ConvertToJSONOption converts an AssertionOption to an Option.
func JSONIgnoreArrayOrder ¶
func JSONIgnoreArrayOrder() JSONOption
JSONIgnoreArrayOrder makes array comparison order-insensitive globally in JSON.
func JSONIgnoreArrayOrderAt ¶
func JSONIgnoreArrayOrderAt(path string) JSONOption
JSONIgnoreArrayOrderAt makes array comparison order-insensitive at the specified JSON path.
func JSONIgnoreFields ¶
func JSONIgnoreFields(fields ...string) JSONOption
JSONIgnoreFields excludes the specified fields from comparison in JSON. Fields can be simple names or JSON paths (e.g., "$.user.id").
func JSONMessage ¶
func JSONMessage(msg string) JSONOption
JSONMessage adds a custom message to the assertion failure output in JSON.
func JSONUpdate ¶
func JSONUpdate() JSONOption
JSONUpdate forces updating the expected file with the actual value in JSON.
type Matcher ¶
type Matcher interface {
// Match returns true if the actual value matches the expected pattern.
Match(actual any) bool
// String returns a description of what this matcher expects.
String() string
}
Matcher defines the interface for custom value matching.
func AnyDateTime ¶
func AnyDateTime() Matcher
AnyDateTime returns a matcher that matches ISO 8601 datetime strings.
func AnyString ¶
func AnyString() Matcher
AnyString returns a matcher that matches any string value.
func AnyUUID ¶
func AnyUUID() Matcher
AnyUUID returns a matcher that matches UUID strings (RFC 4122).
func AnyValue ¶
func AnyValue() Matcher
AnyValue returns a matcher that matches any value including null.
func ParseMatcher ¶
ParseMatcher creates a Matcher from a template expression. The expression is the content between {{ and }}.
type MatcherFactory ¶
MatcherFactory creates a Matcher from arguments extracted from template expression.
type TemplateSegment ¶
type TemplateSegment struct {
Literal string // Literal text (empty if Matcher is set).
Matcher Matcher // Matcher (nil if Literal is set).
}
TemplateSegment represents part of a template string.
type TemplateString ¶
type TemplateString struct {
Segments []TemplateSegment
Original string // For display: "border-left: 6px solid {{anyString}}".
// contains filtered or unexported fields
}
TemplateString represents a string with embedded matchers.
func (*TemplateString) Match ¶
func (t *TemplateString) Match(actual string) bool
Match checks if the actual string matches the template pattern.
func (*TemplateString) String ¶
func (t *TemplateString) String() string
String returns the original template representation.
type YAMLConfig ¶
type YAMLConfig struct {
BaseConfig
}
YAMLConfig holds the configuration for YAML comparison.
type YAMLOption ¶
type YAMLOption func(*YAMLConfig)
YAMLOption is a functional option for configuring YAML comparison.
func ConvertToYAMLOption ¶
func ConvertToYAMLOption(opt AssertionOption) YAMLOption
ConvertToYAMLOption converts an AssertionOption to a YAMLOption.
func YAMLIgnoreArrayOrder ¶
func YAMLIgnoreArrayOrder() YAMLOption
YAMLIgnoreArrayOrder makes array comparison order-insensitive globally.
func YAMLIgnoreArrayOrderAt ¶
func YAMLIgnoreArrayOrderAt(path string) YAMLOption
YAMLIgnoreArrayOrderAt makes array comparison order-insensitive at the specified YAML path.
func YAMLIgnoreFields ¶
func YAMLIgnoreFields(fields ...string) YAMLOption
YAMLIgnoreFields excludes the specified fields from comparison.
func YAMLMessage ¶
func YAMLMessage(msg string) YAMLOption
YAMLMessage adds a custom message to the assertion failure output.
func YAMLUpdate ¶
func YAMLUpdate() YAMLOption
YAMLUpdate forces updating the expected file with the actual value.
Source Files
¶
- assert.go
- assert_collection.go
- assert_eventually.go
- assertion_options.go
- color.go
- compare.go
- diff.go
- file.go
- file_compare.go
- file_options.go
- file_parse.go
- html.go
- html_compare.go
- html_diff.go
- html_options.go
- html_parse.go
- json.go
- json_diff.go
- json_options.go
- json_parse.go
- matchers.go
- options.go
- update.go
- yaml.go
- yaml_diff.go
- yaml_options.go
- yaml_parse.go