apimachineryk8s.io/apimachinery/pkg/util/validation/field/testing Index | Files

package testing

import "k8s.io/apimachinery/pkg/util/validation/field/testing"

Index

Functions

func MatchErrors

func MatchErrors(t *testing.T, want, got field.ErrorList, matcher *Matcher)

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

func (m *Matcher) ByDetailExact() *Matcher

ByDetailExact configures the matcher to match errors by the exact detail string.

func (*Matcher) ByDetailRegexp

func (m *Matcher) ByDetailRegexp() *Matcher

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

func (m *Matcher) ByDetailSubstring() *Matcher

ByDetailSubstring configures the matcher to match errors by a substring of the detail string.

func (*Matcher) ByField

func (m *Matcher) ByField() *Matcher

ByField configures the matcher to match errors by field path.

func (*Matcher) ByOrigin

func (m *Matcher) ByOrigin() *Matcher

ByOrigin configures the matcher to match errors by the origin.

func (*Matcher) ByType

func (m *Matcher) ByType() *Matcher

Exactly configures the matcher to match errors by type.

func (*Matcher) ByValue

func (m *Matcher) ByValue() *Matcher

ByValue configures the matcher to match errors by the errant value.

func (*Matcher) Exactly

func (m *Matcher) Exactly() *Matcher

Exactly configures the matcher to match all fields exactly.

func (*Matcher) Matches

func (m *Matcher) Matches(want, got *field.Error) bool

Matches returns true if the two field.Error objects match according to the configured criteria.

func (*Matcher) Render

func (m *Matcher) Render(e *field.Error) string

Render returns a string representation of the specified Error object, according to the criteria configured in the Matcher.

func (*Matcher) RequireOriginWhenInvalid

func (m *Matcher) RequireOriginWhenInvalid() *Matcher

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.