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

feat: Add test utilities #25

Merged
merged 5 commits into from
Sep 27, 2024
Merged

feat: Add test utilities #25

merged 5 commits into from
Sep 27, 2024

Conversation

nieomylnieja
Copy link
Collaborator

Motivation

Testing validation defined with govy can be a daunting task.
Govy structured errors are information rich, while this is great for end users, it can be a tedious task to verify if one govy.ValidatorError is equal to another govy.ValidatorError.
Often times we might not care about fields like description or even message, we might just want to verify error codes for given properties.

Govy's goal is to not only make the end-user's life better but the programmer's just as well, it would benefit the second party to have a ready-to-use utility which could make the testing process of govy-defined validation a breeze.

Summary

  • Added govytest package.
  • Added tests to some of the internal helpers.
  • Added new builtin rule OneOfProperties which ensures that at least one of the properties provided by getters is set.

Release Notes

Added govytest package which exposes utilities which help test govy validation rules.
It comes with two functions AssertNoError, which ensures no error was produced, and AssertError which checks that the expected errors are equal to the actual govy.ValidatorError.
Added OneOfProperties rule which checks if at least one of the properties is set.

@n9-machine-user n9-machine-user added enhancement New feature or request go Pull requests that update Go code minor New functionality with at most minor brekaing changes labels Sep 27, 2024
Copy link

github-actions bot commented Sep 27, 2024

Test coverage changes:

Package Before After Diff
github.com/nobl9/govy/internal/examples 30% 55% ✔️
github.com/nobl9/govy/internal/nameinfer 15% 16% ✔️
github.com/nobl9/govy/pkg/govy 84% 86% ✔️
github.com/nobl9/govy/pkg/govyconfig 68% 63%
github.com/nobl9/govy/pkg/rules 83% 79%

@nieomylnieja nieomylnieja merged commit 74b9792 into main Sep 27, 2024
6 checks passed
@nieomylnieja nieomylnieja deleted the add-test-utilities branch September 27, 2024 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request go Pull requests that update Go code minor New functionality with at most minor brekaing changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants