(t *testing.T)
| 1392 | } |
| 1393 | |
| 1394 | func TestValidatorValidate(t *testing.T) { |
| 1395 | tests := []struct { |
| 1396 | name string |
| 1397 | v *Validator |
| 1398 | want error |
| 1399 | }{ |
| 1400 | { |
| 1401 | name: "nil validator", |
| 1402 | v: nil, |
| 1403 | want: errors.New("invalid validator: nil"), |
| 1404 | }, |
| 1405 | { |
| 1406 | name: "empty validator", |
| 1407 | v: NewValidator(""), |
| 1408 | want: errors.New("missing name"), |
| 1409 | }, |
| 1410 | } |
| 1411 | |
| 1412 | for _, tst := range tests { |
| 1413 | tc := tst |
| 1414 | t.Run(tc.name, func(t *testing.T) { |
| 1415 | err := tc.v.Validate() |
| 1416 | if err == nil && tc.want == nil { |
| 1417 | return |
| 1418 | } |
| 1419 | if err == nil && tc.want != nil { |
| 1420 | t.Fatalf("v.Validate() got valid, wanted error %v", tc.want) |
| 1421 | } |
| 1422 | if err != nil && tc.want == nil { |
| 1423 | t.Fatalf("v.Validate() got error %v, wanted nil error", err) |
| 1424 | } |
| 1425 | if !strings.Contains(err.Error(), tc.want.Error()) { |
| 1426 | t.Errorf("v.Validate() got error %v, wanted %v", err, tc.want) |
| 1427 | } |
| 1428 | }) |
| 1429 | } |
| 1430 | } |
| 1431 | |
| 1432 | func TestValidatorConfigValue(t *testing.T) { |
| 1433 | var v *Validator |
nothing calls this directly
no test coverage detected