package testing
import "k8s.io/apimachinery/pkg/util/validation/field/testing"
Index ¶
- func MatchErrors(t *testing.T, want, got field.ErrorList, matcher *Matcher)
- type Matcher
- func Match() *Matcher
- func (m *Matcher) ByDetailExact() *Matcher
- func (m *Matcher) ByDetailRegexp() *Matcher
- func (m *Matcher) ByDetailSubstring() *Matcher
- func (m *Matcher) ByField() *Matcher
- func (m *Matcher) ByOrigin() *Matcher
- func (m *Matcher) ByType() *Matcher
- func (m *Matcher) ByValue() *Matcher
- func (m *Matcher) Exactly() *Matcher
- func (m *Matcher) Matches(want, got *field.Error) bool
- func (m *Matcher) Render(e *field.Error) string
- func (m *Matcher) RequireOriginWhenInvalid() *Matcher
Functions ¶
func MatchErrors ¶
MatchErrors compares two ErrorLists with the specified matcher, and fails the test if they don't match. If a given "want" error matches multiple "got" errors, they will all be consumed. This might be OK (e.g. if there are multiple errors on the same field from the same origin) or it might be an insufficiently specific matcher, so these will be logged.
Types ¶
type Matcher ¶
type Matcher struct {
// contains filtered or unexported fields
}
Matcher is a helper for comparing field.Error objects.
func Match ¶
func Match() *Matcher
Match returns a new Matcher.
func (*Matcher) ByDetailExact ¶
ByDetailExact configures the matcher to match errors by the exact detail string.
func (*Matcher) ByDetailRegexp ¶
ByDetailRegexp configures the matcher to match errors by a regular expression of the detail string, where the "want" string is assumed to be a valid regular expression.
func (*Matcher) ByDetailSubstring ¶
ByDetailSubstring configures the matcher to match errors by a substring of the detail string.
func (*Matcher) ByField ¶
ByField configures the matcher to match errors by field path.
func (*Matcher) ByOrigin ¶
ByOrigin configures the matcher to match errors by the origin.
func (*Matcher) ByType ¶
Exactly configures the matcher to match errors by type.
func (*Matcher) ByValue ¶
ByValue configures the matcher to match errors by the errant value.
func (*Matcher) Exactly ¶
Exactly configures the matcher to match all fields exactly.
func (*Matcher) Matches ¶
Matches returns true if the two field.Error objects match according to the configured criteria.
func (*Matcher) Render ¶
Render returns a string representation of the specified Error object, according to the criteria configured in the Matcher.
func (*Matcher) RequireOriginWhenInvalid ¶
RequireOriginWhenInvalid configures the matcher to require the Origin field to be set when the Type is Invalid and the matcher is matching by Origin.
Source Files ¶
match.go
- Version
- v0.33.0-alpha.3
- Published
- Mar 3, 2025
- Platform
- darwin/amd64
- Imports
- 6 packages
- Last checked
- 8 hours ago –
Tools for package owners.