validator icon indicating copy to clipboard operation
validator copied to clipboard

Getting `panic` when I'm trying to mock the `ValidationErrors`

Open joselitofilho opened this issue 3 years ago • 0 comments

  • [x] I have looked at the documentation here first?
  • [x] I have looked at the examples provided that may showcase my question here?

Package version eg. v9, v10:

v10

Issue, Question or Enhancement:

I am trying to mock ValidationErrors and I've got a panic in the errors.go::Error() function in the cast of ve[i] to *fieldError.

So, to mock ValidationErrors we need to use the interface instead.

Code sample, to showcase or reproduce:

I created a mocked implementation for FieldError.

type MockFieldError struct {
	validator.FieldError

	ns string
}

func (fe *MockFieldError) Namespace() string {
	return fe.ns
}

func (fe *MockFieldError) Error() string {
	return "dummyError"
}

joselitofilho avatar Jul 28 '22 11:07 joselitofilho