You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To unit test a validator, we create it using its constructor then use it directly. This is inconvenient for validators that use the DB, the Language, the config or the logger, which are therefore nil and unusable. There is currently no way to set those values in a test without using the entire validation process with validation.Validate().
We should provide a way to init a validator component for tests. Possible solutions:
Export the init(opts *Options) directly. This would drop the requirement to compose with BaseValidator.
If we want to keep the mandatory composition with BaseValidator, we can just add a new exported Init() function to the Validator interface and to BaseValidator. The mandatory composition was initially chosen to promote a simpler and shorter syntax for custom validator, by taking advantage of method overriding. This approach is preferred and would require minimal changes.
Feel free to suggest other solutions or give arguments in favor or against the suggested solution.
The text was updated successfully, but these errors were encountered:
To unit test a validator, we create it using its constructor then use it directly. This is inconvenient for validators that use the DB, the Language, the config or the logger, which are therefore
nil
and unusable. There is currently no way to set those values in a test without using the entire validation process withvalidation.Validate()
.We should provide a way to init a validator component for tests. Possible solutions:
init(opts *Options)
directly. This would drop the requirement to compose withBaseValidator
.BaseValidator
, we can just add a new exportedInit()
function to theValidator
interface and toBaseValidator
. The mandatory composition was initially chosen to promote a simpler and shorter syntax for custom validator, by taking advantage of method overriding. This approach is preferred and would require minimal changes.Feel free to suggest other solutions or give arguments in favor or against the suggested solution.
The text was updated successfully, but these errors were encountered: