mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-18 04:54:54 +00:00
Merge pull request #137017 from lalitc375/revert-dv-native
Revert DV native error matcher and errors
This commit is contained in:
@@ -44,7 +44,6 @@ type ErrorMatcher struct {
|
||||
matchOrigin bool
|
||||
matchDetail func(want, got string) bool
|
||||
requireOriginWhenInvalid bool
|
||||
matchDeclarativeNative bool
|
||||
matchValidationStabilityLevel bool
|
||||
// normalizationRules holds the pre-compiled regex patterns for path normalization.
|
||||
normalizationRules []NormalizationRule
|
||||
@@ -88,9 +87,6 @@ func (m ErrorMatcher) Matches(want, got *Error) bool {
|
||||
if m.matchDetail != nil && !m.matchDetail(want.Detail, got.Detail) {
|
||||
return false
|
||||
}
|
||||
if m.matchDeclarativeNative && want.DeclarativeNative != got.DeclarativeNative {
|
||||
return false
|
||||
}
|
||||
if m.matchValidationStabilityLevel && want.ValidationStabilityLevel != got.ValidationStabilityLevel {
|
||||
return false
|
||||
}
|
||||
@@ -157,10 +153,6 @@ func (m ErrorMatcher) Render(e *Error) string {
|
||||
comma()
|
||||
buf.WriteString(fmt.Sprintf("Detail=%q", e.Detail))
|
||||
}
|
||||
if m.matchDeclarativeNative {
|
||||
comma()
|
||||
buf.WriteString(fmt.Sprintf("DeclarativeNative=%t", e.DeclarativeNative))
|
||||
}
|
||||
if m.matchValidationStabilityLevel {
|
||||
comma()
|
||||
buf.WriteString(fmt.Sprintf("ValidationStabilityLevel=%s", e.ValidationStabilityLevel))
|
||||
@@ -241,13 +233,6 @@ func (m ErrorMatcher) RequireOriginWhenInvalid() ErrorMatcher {
|
||||
return m
|
||||
}
|
||||
|
||||
// ByDeclarativeNative returns a derived ErrorMatcher which also matches by the DeclarativeNative
|
||||
// value of field errors.
|
||||
func (m ErrorMatcher) ByDeclarativeNative() ErrorMatcher {
|
||||
m.matchDeclarativeNative = true
|
||||
return m
|
||||
}
|
||||
|
||||
// ByValidationStabilityLevel returns a derived ErrorMatcher which also matches by the validation stability level
|
||||
// value of field errors.
|
||||
func (m ErrorMatcher) ByValidationStabilityLevel() ErrorMatcher {
|
||||
|
||||
@@ -303,26 +303,6 @@ func TestErrorMatcher_Matches(t *testing.T) {
|
||||
wantedErr: baseErr,
|
||||
actualErr: &Error{Type: ErrorTypeRequired, Field: "field", BadValue: "value", Detail: "detail", Origin: "origin"},
|
||||
matches: false,
|
||||
}, {
|
||||
name: "ByDeclarativeNative: match",
|
||||
matcher: ErrorMatcher{}.ByDeclarativeNative(),
|
||||
wantedErr: func() *Error {
|
||||
e := baseErr()
|
||||
e.DeclarativeNative = true
|
||||
return e
|
||||
},
|
||||
actualErr: &Error{DeclarativeNative: true},
|
||||
matches: true,
|
||||
}, {
|
||||
name: "ByDeclarativeNative: no match",
|
||||
matcher: ErrorMatcher{}.ByDeclarativeNative(),
|
||||
wantedErr: func() *Error {
|
||||
e := baseErr()
|
||||
e.DeclarativeNative = true
|
||||
return e
|
||||
},
|
||||
actualErr: &Error{DeclarativeNative: false},
|
||||
matches: false,
|
||||
}, {
|
||||
name: "RequireOriginWhenInvalid: match",
|
||||
matcher: ErrorMatcher{}.ByOrigin().RequireOriginWhenInvalid(),
|
||||
@@ -426,17 +406,6 @@ func TestErrorMatcher_Test(t *testing.T) {
|
||||
want: ErrorList{Invalid(NewPath("f").Index(0).Child("x", "a"), nil, "")},
|
||||
got: ErrorList{Invalid(NewPath("f").Index(1).Child("a"), "v", "d")},
|
||||
expectedErrors: []string{"expected an error matching:", "unmatched error:"},
|
||||
}, {
|
||||
name: "declarative native: match",
|
||||
matcher: ErrorMatcher{}.ByDeclarativeNative(),
|
||||
want: ErrorList{{DeclarativeNative: true}},
|
||||
got: ErrorList{{DeclarativeNative: true}},
|
||||
}, {
|
||||
name: "declarative native: no match",
|
||||
matcher: ErrorMatcher{}.ByDeclarativeNative(),
|
||||
want: ErrorList{{DeclarativeNative: true}},
|
||||
got: ErrorList{{DeclarativeNative: false}},
|
||||
expectedErrors: []string{"expected an error matching:", "unmatched error:"},
|
||||
}, {
|
||||
name: "validation level: match",
|
||||
matcher: ErrorMatcher{}.ByValidationStabilityLevel(),
|
||||
@@ -575,25 +544,6 @@ func TestErrorMatcher_Render(t *testing.T) {
|
||||
expected: `{Field="f[0].x.a"}`,
|
||||
},
|
||||
{
|
||||
name: "with covered by declarative",
|
||||
matcher: ErrorMatcher{}.ByDeclarativeNative(),
|
||||
err: func() *Error {
|
||||
e := Invalid(NewPath("field"), "value", "detail")
|
||||
e.DeclarativeNative = true
|
||||
return e
|
||||
}(),
|
||||
expected: `{DeclarativeNative=true}`,
|
||||
},
|
||||
{
|
||||
name: "all fields with covered by declarative",
|
||||
matcher: ErrorMatcher{}.ByType().ByField().ByValue().ByOrigin().ByDetailExact().ByDeclarativeNative(),
|
||||
err: func() *Error {
|
||||
e := Invalid(NewPath("field"), "value", "detail").WithOrigin("origin")
|
||||
e.DeclarativeNative = true
|
||||
return e
|
||||
}(),
|
||||
expected: `{Type="Invalid value", Field="field", Value="value", Origin="origin", Detail="detail", DeclarativeNative=true}`,
|
||||
}, {
|
||||
name: "requireOriginWhenInvalid with origin",
|
||||
matcher: ErrorMatcher{}.ByOrigin().RequireOriginWhenInvalid(),
|
||||
err: Invalid(NewPath("field"), "value", "detail").WithOrigin("origin"),
|
||||
|
||||
@@ -56,10 +56,6 @@ type Error struct {
|
||||
// that should also be caught by declarative validation.
|
||||
CoveredByDeclarative bool
|
||||
|
||||
// DeclarativeNative is true when this error originates from a declarative-native validation.
|
||||
// This field is used to distinguish errors that are exclusively declarative and lack an imperative counterpart.
|
||||
DeclarativeNative bool
|
||||
|
||||
// ValidationStabilityLevel denotes the validation stability level of the declarative validation from this error is returned. This should be used in the declarative validations only.
|
||||
ValidationStabilityLevel ValidationStabilityLevel
|
||||
}
|
||||
@@ -484,20 +480,6 @@ func (list ErrorList) ExtractCoveredByDeclarative() ErrorList {
|
||||
return newList
|
||||
}
|
||||
|
||||
// MarkDeclarativeNative marks the error as originating from a declarative-native validation.
|
||||
func (e *Error) MarkDeclarativeNative() *Error {
|
||||
e.DeclarativeNative = true
|
||||
return e
|
||||
}
|
||||
|
||||
// MarkDeclarativeNative marks all errors in the list as originating from declarative-native validations.
|
||||
func (list ErrorList) MarkDeclarativeNative() ErrorList {
|
||||
for _, err := range list {
|
||||
err.DeclarativeNative = true
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// MarkAlpha marks the error as an alpha validation error.
|
||||
func (e *Error) MarkAlpha() *Error {
|
||||
e.ValidationStabilityLevel = stabilityLevelAlpha
|
||||
|
||||
Reference in New Issue
Block a user