@@ -140,7 +140,7 @@ func (s *ValidationTestBuilder) ValidateFixtures() {
140
140
}
141
141
s .ValueFuzzed (v )
142
142
vt := & ValidationTester {ValidationTestBuilder : s , value : v }
143
- byPath := vt .ValidateFalseArgsByPath ()
143
+ byPath := vt .validateFalseArgsByPath ()
144
144
got [t .String ()] = byPath
145
145
}
146
146
@@ -311,27 +311,6 @@ func (v *ValidationTester) ExpectValid() *ValidationTester {
311
311
return v
312
312
}
313
313
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
-
335
314
// ExpectInvalid validates the value and calls t.Errorf if want does not match the actual errors.
336
315
// Returns ValidationTester to support call chaining.
337
316
func (v * ValidationTester ) ExpectInvalid (want ... * field.Error ) * ValidationTester {
@@ -340,40 +319,26 @@ func (v *ValidationTester) ExpectInvalid(want ...*field.Error) *ValidationTester
340
319
return v .expectInvalid (byFullError , want ... )
341
320
}
342
321
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 {
358
323
v .T .Helper ()
359
324
360
325
v .T .Run (fmt .Sprintf ("%T" , v .value ), func (t * testing.T ) {
361
326
t .Helper ()
362
327
363
- byPath := v .ValidateFalseArgsByPath ()
328
+ actualByPath := v .validateFalseArgsByPath ()
364
329
// ensure args are sorted
365
- for _ , args := range validateFalseArgsByPath {
330
+ for _ , args := range expectedByPath {
366
331
sort .Strings (args )
367
332
}
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 ])))
370
335
}
371
336
372
337
})
373
338
return v
374
339
}
375
340
376
- func (v * ValidationTester ) ValidateFalseArgsByPath () map [string ][]string {
341
+ func (v * ValidationTester ) validateFalseArgsByPath () map [string ][]string {
377
342
byPath := map [string ][]string {}
378
343
errs := v .validate ()
379
344
for _ , e := range errs {
@@ -537,10 +502,6 @@ func (v *ValidationTester) expectInvalid(matcher matcher, errs ...*field.Error)
537
502
538
503
type matcher func (err * field.Error ) string
539
504
540
- func byDetail (err * field.Error ) string {
541
- return err .Detail
542
- }
543
-
544
505
func byFullError (err * field.Error ) string {
545
506
return err .Error ()
546
507
}
0 commit comments