1
0
mirror of https://github.com/volatiletech/authboss.git synced 2025-07-15 01:24:33 +02:00

Add some validation helpers

This commit is contained in:
Aaron L
2018-04-30 18:19:19 -07:00
parent 08645c0811
commit f594d1d556
2 changed files with 20 additions and 0 deletions

View File

@ -18,12 +18,20 @@ type Validator interface {
}
// FieldError describes an error on a field
// Typically .Error() has both Name() and Err() together, hence the reason
// for separation.
type FieldError interface {
error
Name() string
Err() error
}
// ErrorMap is a shortcut to change []error into ErrorList and call Map on it since
// this is a common operation.
func ErrorMap(e []error) map[string][]string {
return ErrorList(e).Map()
}
// ErrorList is simply a slice of errors with helpers.
type ErrorList []error

View File

@ -78,3 +78,15 @@ func TestErrorList_Map(t *testing.T) {
t.Error("Wrong unkown error at 0:", unknownErrs[0])
}
}
func TestErrorList_MapHelper(t *testing.T) {
t.Parallel()
errList := []error{
mockFieldError{"username", errors.New("")},
mockFieldError{"username", errors.New("")},
mockFieldError{"password", errors.New("")},
}
var _ map[string][]string = ErrorMap(errList)
}