Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testutil: cannot init a validator component #239

Open
System-Glitch opened this issue Feb 5, 2025 · 0 comments
Open

testutil: cannot init a validator component #239

System-Glitch opened this issue Feb 5, 2025 · 0 comments
Labels
enhancement Enhancement of existing feature good first issue Good for newcomers

Comments

@System-Glitch
Copy link
Member

System-Glitch commented Feb 5, 2025

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.

@System-Glitch System-Glitch added enhancement Enhancement of existing feature good first issue Good for newcomers labels Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement of existing feature good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant