Skip to content

Commit abad982

Browse files
authored
Merge pull request kubernetes#130857 from thockin/kk_small_vg_diffs
Port small deltas from validation-gen dev branch to master
2 parents f007012 + 8f69d59 commit abad982

File tree

39 files changed

+913
-907
lines changed

39 files changed

+913
-907
lines changed

staging/src/k8s.io/apimachinery/pkg/api/validate/each_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func TestEachSliceVal(t *testing.T) {
5959
}
6060

6161
func testEachSliceVal[T any](t *testing.T, name string, input []T) {
62+
t.Helper()
6263
var zero T
6364
t.Run(fmt.Sprintf("%s(%T)", name, zero), func(t *testing.T) {
6465
calls := 0
@@ -77,6 +78,7 @@ func testEachSliceVal[T any](t *testing.T, name string, input []T) {
7778
}
7879

7980
func testEachSliceValUpdate[T any](t *testing.T, name string, input []T) {
81+
t.Helper()
8082
var zero T
8183
t.Run(fmt.Sprintf("%s(%T)", name, zero), func(t *testing.T) {
8284
calls := 0
@@ -116,6 +118,7 @@ func TestEachMapVal(t *testing.T) {
116118
}
117119

118120
func testEachMapVal[T any](t *testing.T, name string, input map[string]T) {
121+
t.Helper()
119122
var zero T
120123
t.Run(fmt.Sprintf("%s(%T)", name, zero), func(t *testing.T) {
121124
calls := 0
@@ -141,6 +144,7 @@ func TestEachMapKey(t *testing.T) {
141144
}
142145

143146
func testEachMapKey[K ~string, V any](t *testing.T, name string, input map[K]V) {
147+
t.Helper()
144148
var zero K
145149
t.Run(fmt.Sprintf("%s(%T)", name, zero), func(t *testing.T) {
146150
calls := 0

staging/src/k8s.io/apimachinery/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
}

staging/src/k8s.io/apimachinery/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
}

staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ type Error struct {
4444
// - A structured format using "format=<dash-style-identifier>" for validation errors related to specific formats
4545
// (e.g., "format=dns-label", "format=qualified-name")
4646
//
47+
// If the Origin corresponds to an existing declarative validation tag or JSON Schema keyword,
48+
// use that same name for consistency.
49+
//
4750
// Origin should be set in the most deeply nested validation function that
4851
// can still identify the unique source of the error.
4952
Origin string
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
{
2-
"*withfieldvalidations.T1": {
3-
"s": [
4-
"field T1.S"
5-
],
6-
"t2": [
7-
"field T1.T2"
8-
],
9-
"t2.s": [
10-
"field T2.S"
11-
],
12-
"t3": [
13-
"field T1.T3"
14-
]
15-
},
16-
"*withfieldvalidations.T2": {
17-
"s": [
18-
"field T2.S"
19-
]
20-
},
21-
"*withfieldvalidations.T4": {
22-
"s": [
23-
"field T4.S"
24-
]
25-
}
26-
}
2+
"*withfieldvalidations.T1": {
3+
"s": [
4+
"field T1.S"
5+
],
6+
"t2": [
7+
"field T1.T2"
8+
],
9+
"t2.s": [
10+
"field T2.S"
11+
],
12+
"t3": [
13+
"field T1.T3"
14+
]
15+
},
16+
"*withfieldvalidations.T2": {
17+
"s": [
18+
"field T2.S"
19+
]
20+
},
21+
"*withfieldvalidations.T4": {
22+
"s": [
23+
"field T4.S"
24+
]
25+
}
26+
}
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"*withtypevalidations.E1": {
3-
"": [
4-
"type E1"
5-
]
6-
},
7-
"*withtypevalidations.T1": {
8-
"": [
9-
"type T1"
10-
],
11-
"s": [
12-
"field T1.S"
13-
]
14-
}
15-
}
2+
"*withtypevalidations.E1": {
3+
"": [
4+
"type E1"
5+
]
6+
},
7+
"*withtypevalidations.T1": {
8+
"": [
9+
"type T1"
10+
],
11+
"s": [
12+
"field T1.S"
13+
]
14+
}
15+
}

0 commit comments

Comments
 (0)