| Conditions | 3 |
| Total Lines | 19 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | package validation_test |
||
| 18 | func (companies Companies) Validate(validator *validation.Validator) error { |
||
| 19 | violations := validation.ViolationList{} |
||
| 20 | |||
| 21 | for i, company := range companies { |
||
| 22 | err := validator.AtIndex(i).Validate( |
||
| 23 | validation.StringProperty("name", &company.Name, it.IsNotBlank()), |
||
| 24 | validation.StringProperty("address", &company.Address, it.IsNotBlank(), it.HasMinLength(3)), |
||
| 25 | ) |
||
| 26 | // appending violations from err |
||
| 27 | err = violations.AppendFromError(err) |
||
| 28 | // if append returns a non-nil error we should stop validation because an internal error occurred |
||
| 29 | if err != nil { |
||
| 30 | return err |
||
| 31 | } |
||
| 32 | } |
||
| 33 | |||
| 34 | // we should always convert ViolationList into error by calling the AsError method |
||
| 35 | // otherwise empty violations list will be interpreted as an error |
||
| 36 | return violations.AsError() |
||
| 37 | } |
||
| 55 |