martini-contrib / binding

Martini handler for mapping and validating a raw request into a structure.
MIT License
140 stars 47 forks source link

Export NewErrors to make writing unit tests against validators easier #21

Closed attilaolah closed 10 years ago

attilaolah commented 10 years ago

This way, when someone writes unit tests against structs that implements the binding.Validator interface, they don't have to manually set up the *binding.Errors parameter themselves. They can simply call binding.NewError().

Note that this method is only intended to be used in tests. binding will take care of initialising the *Errors parameter before calling Validate.

Let me know if anyone has a better idea. I don't like exporting too much, and it bothers me somewhat that this is needed purely for testing. But I can't think of anything better.

mholt commented 10 years ago

Well, it is rather conventional in Go to export constructor functions in this fashion. I don't mind. In a future commit I'll add some godoc comments to the function and mention that it's really only useful for testing; in other cases the errors struct is provided for you.

Either way, merging in. Thanks!