package testing
import "k8s.io/apimachinery/pkg/util/validation/field/testing"
Index ¶
- type ErrorMatcher
- func (m ErrorMatcher) ByDetailExact() ErrorMatcher
- func (m ErrorMatcher) ByDetailRegexp() ErrorMatcher
- func (m ErrorMatcher) ByDetailSubstring() ErrorMatcher
- func (m ErrorMatcher) ByField() ErrorMatcher
- func (m ErrorMatcher) ByOrigin() ErrorMatcher
- func (m ErrorMatcher) ByType() ErrorMatcher
- func (m ErrorMatcher) ByValue() ErrorMatcher
- func (m ErrorMatcher) Exactly() ErrorMatcher
- func (m ErrorMatcher) Matches(want, got *field.Error) bool
- func (m ErrorMatcher) Render(e *field.Error) string
- func (m ErrorMatcher) RequireOriginWhenInvalid() ErrorMatcher
- func (m ErrorMatcher) Test(tb testing.TB, want, got field.ErrorList)
Types ¶
type ErrorMatcher ¶
type ErrorMatcher struct {
// contains filtered or unexported fields
}
ErrorMatcher is a helper for comparing field.Error objects.
func (ErrorMatcher) ByDetailExact ¶
func (m ErrorMatcher) ByDetailExact() ErrorMatcher
ByDetailExact returns a derived ErrorMatcher which also matches errors by the exact detail string.
func (ErrorMatcher) ByDetailRegexp ¶
func (m ErrorMatcher) ByDetailRegexp() ErrorMatcher
ByDetailRegexp returns a derived ErrorMatcher which also matches errors by a regular expression of the detail string, where the "want" string is assumed to be a valid regular expression.
func (ErrorMatcher) ByDetailSubstring ¶
func (m ErrorMatcher) ByDetailSubstring() ErrorMatcher
ByDetailSubstring returns a derived ErrorMatcher which also matches errors by a substring of the detail string.
func (ErrorMatcher) ByField ¶
func (m ErrorMatcher) ByField() ErrorMatcher
ByField returns a derived ErrorMatcher which also matches by field path.
func (ErrorMatcher) ByOrigin ¶
func (m ErrorMatcher) ByOrigin() ErrorMatcher
ByOrigin returns a derived ErrorMatcher which also matches by the origin.
func (ErrorMatcher) ByType ¶
func (m ErrorMatcher) ByType() ErrorMatcher
ByType returns a derived ErrorMatcher which also matches by type.
func (ErrorMatcher) ByValue ¶
func (m ErrorMatcher) ByValue() ErrorMatcher
ByValue returns a derived ErrorMatcher which also matches by the errant value.
func (ErrorMatcher) Exactly ¶
func (m ErrorMatcher) Exactly() ErrorMatcher
Exactly returns a derived ErrorMatcher which matches all fields exactly.
func (ErrorMatcher) Matches ¶
func (m ErrorMatcher) Matches(want, got *field.Error) bool
Matches returns true if the two field.Error objects match according to the configured criteria.
func (ErrorMatcher) Render ¶
func (m ErrorMatcher) Render(e *field.Error) string
Render returns a string representation of the specified Error object, according to the criteria configured in the ErrorMatcher.
func (ErrorMatcher) RequireOriginWhenInvalid ¶
func (m ErrorMatcher) RequireOriginWhenInvalid() ErrorMatcher
RequireOriginWhenInvalid returns a derived ErrorMatcher which also requires the Origin field to be set when the Type is Invalid and the matcher is matching by Origin.
func (ErrorMatcher) Test ¶
func (m ErrorMatcher) Test(tb testing.TB, want, got field.ErrorList)
Test compares two ErrorLists by the criteria configured in this 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.
Source Files ¶
error_matcher.go
- Version
- v0.33.0-beta.0
- Published
- Mar 11, 2025
- Platform
- linux/amd64
- Imports
- 6 packages
- Last checked
- 1 day ago –
Tools for package owners.