Add exported function to remove rules #316
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey there!
I'm using gqlparser in another project. There, I add a number of custom rules on top of the existing ones.
I'm having an issue with writing tests though. Since the
rules
global variable is not exported, and there exists noRemoveRule
functionality, my tests start to interfere with each other as this global state is never reset between test cases.For that reason, I'd like to add this MR, so I can clear this state between runs.
Things I've considered:
rules
global variable. Decided against that as that would be a much more impactful changeinit()
functions, to something else so that they can be re-initialized.RemoveRule
that does a string-based match on the rule name, and remove it (actually filter it out on copy) from the list. Then re-assign the still unexported field to this new, filtered, list.Adding meaningful tests for this was hard as the tests for the validator are not in the same package (
validator
vsvalidator_test
). I added tests to assure there are no errors when running theRemoveRule
function both when there is a match on a rule, and when there is not.If a different approach is preferred I'm happy to alter the MR. I thought I'd start small and get your thoughts on the right strategy before trying to rewrite too much.
I have: