Use origin in validateFalse's own test

This commit is contained in:
Tim Hockin 2025-03-16 14:27:31 -07:00
parent d1d77cd553
commit 4c0c2d21ea
No known key found for this signature in database
2 changed files with 5 additions and 3 deletions

View File

@ -30,6 +30,6 @@ func FixedResult[T any](_ context.Context, op operation.Operation, fldPath *fiel
return nil
}
return field.ErrorList{
field.Invalid(fldPath, value, "forced failure: "+arg),
field.Invalid(fldPath, value, "forced failure: "+arg).WithOrigin("validateFalse"),
}
}

View File

@ -121,6 +121,7 @@ func TestFixedResult(t *testing.T) {
pass: true,
}}
matcher := field.ErrorMatcher{}.ByOrigin().ByDetailExact()
for i, tc := range cases {
result := FixedResult(context.Background(), operation.Operation{}, field.NewPath("fldpath"), tc.value, nil, tc.pass, "detail string")
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))
continue
}
if want, got := "forced failure: detail string", result[0].Detail; got != want {
t.Errorf("case %d: wrong error, expected: %q, got: %q", i, want, got)
wantErrorList := field.ErrorList{
field.Invalid(field.NewPath("fldpath"), tc.value, "forced failure: detail string").WithOrigin("validateFalse"),
}
matcher.Test(t, wantErrorList, result)
}
}
}