mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Use origin in validateFalse's own test
This commit is contained in:
parent
d1d77cd553
commit
4c0c2d21ea
@ -30,6 +30,6 @@ func FixedResult[T any](_ context.Context, op operation.Operation, fldPath *fiel
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return field.ErrorList{
|
return field.ErrorList{
|
||||||
field.Invalid(fldPath, value, "forced failure: "+arg),
|
field.Invalid(fldPath, value, "forced failure: "+arg).WithOrigin("validateFalse"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,6 +121,7 @@ func TestFixedResult(t *testing.T) {
|
|||||||
pass: true,
|
pass: true,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
matcher := field.ErrorMatcher{}.ByOrigin().ByDetailExact()
|
||||||
for i, tc := range cases {
|
for i, tc := range cases {
|
||||||
result := FixedResult(context.Background(), operation.Operation{}, field.NewPath("fldpath"), tc.value, nil, tc.pass, "detail string")
|
result := FixedResult(context.Background(), operation.Operation{}, field.NewPath("fldpath"), tc.value, nil, tc.pass, "detail string")
|
||||||
if len(result) != 0 && tc.pass {
|
if len(result) != 0 && tc.pass {
|
||||||
@ -136,9 +137,10 @@ func TestFixedResult(t *testing.T) {
|
|||||||
t.Errorf("case %d: unexepected multi-error: %v", i, fmtErrs(result))
|
t.Errorf("case %d: unexepected multi-error: %v", i, fmtErrs(result))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if want, got := "forced failure: detail string", result[0].Detail; got != want {
|
wantErrorList := field.ErrorList{
|
||||||
t.Errorf("case %d: wrong error, expected: %q, got: %q", i, want, got)
|
field.Invalid(field.NewPath("fldpath"), tc.value, "forced failure: detail string").WithOrigin("validateFalse"),
|
||||||
}
|
}
|
||||||
|
matcher.Test(t, wantErrorList, result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user