Skip to content

Commit 769d71b

Browse files
thockinyongruilin
authored andcommitted
Remove unused Expect methods in testscheme
1 parent 105dd3b commit 769d71b

File tree

2 files changed

+10
-49
lines changed
  • staging/src/k8s.io/code-generator/cmd/validation-gen

2 files changed

+10
-49
lines changed

staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/subfield/nonincluded/doc_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
func TestSubfieldObjectMetaValidationWithValidateFalse(t *testing.T) {
2424
st := localSchemeBuilder.Test(t)
2525

26-
st.Value(&Struct{}).
27-
// check for subfield +k8s:validateFalse validation on Struct.(other.StructType).StringField
28-
ExpectValidateFalse("subfield Struct.(other.StructType).StringField")
26+
st.Value(&Struct{}).ExpectValidateFalseByPath(map[string][]string{
27+
"other.StructType.stringField": {"subfield Struct.(other.StructType).StringField"},
28+
})
2929
}

staging/src/k8s.io/code-generator/cmd/validation-gen/testscheme/testscheme.go

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (s *ValidationTestBuilder) ValidateFixtures() {
140140
}
141141
s.ValueFuzzed(v)
142142
vt := &ValidationTester{ValidationTestBuilder: s, value: v}
143-
byPath := vt.ValidateFalseArgsByPath()
143+
byPath := vt.validateFalseArgsByPath()
144144
got[t.String()] = byPath
145145
}
146146

@@ -311,27 +311,6 @@ func (v *ValidationTester) ExpectValid() *ValidationTester {
311311
return v
312312
}
313313

314-
// ExpectValidAt validates the value and calls t.Errorf for any validation errors at the given path.
315-
// Returns ValidationTester to support call chaining.
316-
func (v *ValidationTester) ExpectValidAt(fldPath *field.Path) *ValidationTester {
317-
v.T.Helper()
318-
319-
v.T.Run(fmt.Sprintf("%T.%v", v.value, fldPath), func(t *testing.T) {
320-
t.Helper()
321-
322-
var got field.ErrorList
323-
for _, e := range v.validate() {
324-
if e.Field == fldPath.String() {
325-
got = append(got, e)
326-
}
327-
}
328-
if len(got) > 0 {
329-
t.Errorf("want no errors at %v, got: %v", fldPath, got)
330-
}
331-
})
332-
return v
333-
}
334-
335314
// ExpectInvalid validates the value and calls t.Errorf if want does not match the actual errors.
336315
// Returns ValidationTester to support call chaining.
337316
func (v *ValidationTester) ExpectInvalid(want ...*field.Error) *ValidationTester {
@@ -340,40 +319,26 @@ func (v *ValidationTester) ExpectInvalid(want ...*field.Error) *ValidationTester
340319
return v.expectInvalid(byFullError, want...)
341320
}
342321

343-
// ExpectValidateFalse validates the value and calls t.Errorf if the actual errors do not
344-
// match the given validateFalseArgs. For example, if the value to validate has a
345-
// single `+validateFalse="type T1"` tag, ExpectValidateFalse("type T1") will pass.
346-
// Returns ValidationTester to support call chaining.
347-
func (v *ValidationTester) ExpectValidateFalse(validateFalseArgs ...string) *ValidationTester {
348-
v.T.Helper()
349-
350-
var want []*field.Error
351-
for _, s := range validateFalseArgs {
352-
want = append(want, field.Invalid(nil, "", fmt.Sprintf("forced failure: %s", s)))
353-
}
354-
return v.expectInvalid(byDetail, want...)
355-
}
356-
357-
func (v *ValidationTester) ExpectValidateFalseByPath(validateFalseArgsByPath map[string][]string) *ValidationTester {
322+
func (v *ValidationTester) ExpectValidateFalseByPath(expectedByPath map[string][]string) *ValidationTester {
358323
v.T.Helper()
359324

360325
v.T.Run(fmt.Sprintf("%T", v.value), func(t *testing.T) {
361326
t.Helper()
362327

363-
byPath := v.ValidateFalseArgsByPath()
328+
actualByPath := v.validateFalseArgsByPath()
364329
// ensure args are sorted
365-
for _, args := range validateFalseArgsByPath {
330+
for _, args := range expectedByPath {
366331
sort.Strings(args)
367332
}
368-
if !cmp.Equal(validateFalseArgsByPath, byPath) {
369-
t.Errorf("validateFalse args, grouped by field path, differed from expected:\n%s\n", cmp.Diff(validateFalseArgsByPath, byPath, cmpopts.SortMaps(stdcmp.Less[string])))
333+
if !cmp.Equal(expectedByPath, actualByPath) {
334+
t.Errorf("validateFalse args, grouped by field path, differed from expected:\n%s\n", cmp.Diff(expectedByPath, actualByPath, cmpopts.SortMaps(stdcmp.Less[string])))
370335
}
371336

372337
})
373338
return v
374339
}
375340

376-
func (v *ValidationTester) ValidateFalseArgsByPath() map[string][]string {
341+
func (v *ValidationTester) validateFalseArgsByPath() map[string][]string {
377342
byPath := map[string][]string{}
378343
errs := v.validate()
379344
for _, e := range errs {
@@ -537,10 +502,6 @@ func (v *ValidationTester) expectInvalid(matcher matcher, errs ...*field.Error)
537502

538503
type matcher func(err *field.Error) string
539504

540-
func byDetail(err *field.Error) string {
541-
return err.Detail
542-
}
543-
544505
func byFullError(err *field.Error) string {
545506
return err.Error()
546507
}

0 commit comments

Comments
 (0)