Skip to content

Commit b63ba07

Browse files
thockink8s-publishing-bot
authored andcommitted
Use origin in validateFalse's own test
Kubernetes-commit: 4c0c2d21ea6fb2baf18619ac51e50f26e16d4545
1 parent beddba4 commit b63ba07

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pkg/api/validate/testing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ func FixedResult[T any](_ context.Context, op operation.Operation, fldPath *fiel
3030
return nil
3131
}
3232
return field.ErrorList{
33-
field.Invalid(fldPath, value, "forced failure: "+arg),
33+
field.Invalid(fldPath, value, "forced failure: "+arg).WithOrigin("validateFalse"),
3434
}
3535
}

pkg/api/validate/testing_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func TestFixedResult(t *testing.T) {
121121
pass: true,
122122
}}
123123

124+
matcher := field.ErrorMatcher{}.ByOrigin().ByDetailExact()
124125
for i, tc := range cases {
125126
result := FixedResult(context.Background(), operation.Operation{}, field.NewPath("fldpath"), tc.value, nil, tc.pass, "detail string")
126127
if len(result) != 0 && tc.pass {
@@ -136,9 +137,10 @@ func TestFixedResult(t *testing.T) {
136137
t.Errorf("case %d: unexepected multi-error: %v", i, fmtErrs(result))
137138
continue
138139
}
139-
if want, got := "forced failure: detail string", result[0].Detail; got != want {
140-
t.Errorf("case %d: wrong error, expected: %q, got: %q", i, want, got)
140+
wantErrorList := field.ErrorList{
141+
field.Invalid(field.NewPath("fldpath"), tc.value, "forced failure: detail string").WithOrigin("validateFalse"),
141142
}
143+
matcher.Test(t, wantErrorList, result)
142144
}
143145
}
144146
}

0 commit comments

Comments
 (0)