I have a function that parses different fields in the array of type ValidationError
to generate custom error messages something like the following function.
func foo(err validator.ValidationErrors) []string {
var errStr []string
for _, e := range err {
tag := e.Tag()
field := e.Field()
errStr = append(errStr, tag + ":" + field)
}
return errStr
}
I want to write unit test for this function to ensure that the custom message is as expected. How can I mock a variable of type validator.ValidationError
. Below is the structure of ValidationError:
type ValidationErrors []FieldError
FieldError
is an interface which contains functions (such as Tag()
, Field()
, etc.) to get error details.