update all validation tests

This commit is contained in:
Aneurin Barker Snook
2023-11-19 20:42:48 +00:00
parent db902e3c1c
commit 40482060ac
10 changed files with 24 additions and 32 deletions
+4 -8
View File
@@ -1,20 +1,16 @@
package validate
import (
"errors"
)
// Validation error.
var (
ErrTooFewChars = errors.New("too few characters")
ErrTooManyChars = errors.New("too many characters")
ErrMustBeLonger = NewError("must be at least %d characters")
ErrMustBeShorter = NewError("must be no more than %d characters")
)
// MaxLength validates the length of a string as being less than or equal to a given maximum.
func MaxLength(l int) func(string) error {
return func(value string) error {
if len(value) > l {
return ErrTooManyChars
return ErrMustBeShorter.With(l)
}
return nil
}
@@ -24,7 +20,7 @@ func MaxLength(l int) func(string) error {
func MinLength(l int) func(string) error {
return func(value string) error {
if len(value) < l {
return ErrTooFewChars
return ErrMustBeLonger.With(l)
}
return nil
}