-
Notifications
You must be signed in to change notification settings - Fork 13
test: add test to assert empty intersection invalid #523
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
base: main
Are you sure you want to change the base?
Conversation
Add unit test to assert that empty intersection / empty union model are marked as invalid.
WalkthroughAdded test cases validating that the weighted graph builder properly rejects invalid graph models where intersection or union nodes contain no children. Test file enhanced with new subtests under an existing test function alongside necessary import alias for OpenFGA v1 API types. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
pkg/go/graph/weighted_graph_builder_test.go (2)
1939-1969: Use more specific error assertion.The test currently uses
require.Error(t, err)which only checks that some error occurred. For consistency with similar tests in this file (see lines 408, 1917, 1937), consider using a more specific assertion to verify the expected error type or message.♻️ Suggested improvement
If the builder returns
ErrInvalidModelfor empty intersections:wgb := NewWeightedAuthorizationModelGraphBuilder() _, err := wgb.Build(authorizationModel) - require.Error(t, err) + require.ErrorIs(t, err, ErrInvalidModel)Alternatively, if there's a specific error message:
wgb := NewWeightedAuthorizationModelGraphBuilder() _, err := wgb.Build(authorizationModel) - require.Error(t, err) + require.ErrorContains(t, err, "empty intersection")
1970-2000: Use more specific error assertion.Similar to the
empty_intersectiontest, this test usesrequire.Error(t, err)which only checks that some error occurred. Consider using a more specific assertion for consistency with other tests in this file.♻️ Suggested improvement
If the builder returns
ErrInvalidModelfor empty unions:wgb := NewWeightedAuthorizationModelGraphBuilder() _, err := wgb.Build(authorizationModel) - require.Error(t, err) + require.ErrorIs(t, err, ErrInvalidModel)Alternatively, if there's a specific error message:
wgb := NewWeightedAuthorizationModelGraphBuilder() _, err := wgb.Build(authorizationModel) - require.Error(t, err) + require.ErrorContains(t, err, "empty union")
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
pkg/go/graph/weighted_graph_builder_test.go
🧰 Additional context used
🧬 Code graph analysis (1)
pkg/go/graph/weighted_graph_builder_test.go (1)
pkg/go/graph/weighted_graph_builder.go (1)
NewWeightedAuthorizationModelGraphBuilder(19-21)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Analyze (go)
🔇 Additional comments (1)
pkg/go/graph/weighted_graph_builder_test.go (1)
6-6: LGTM! Import is necessary for the new test cases.The import alias is correctly added to support direct construction of authorization models using proto types in the new tests.
Description
What problem is being solved?
Ensure weighted graph prevents case where model has relation with empty intersection / union as it can cause check / list objects / list users algorithm to fail. We had seen problems with OpenFGA's type system. We want to ensure this will not be a regression when we switch to use weighted graph as replacement for typesystem.
How is it being solved?
Add unit test to assert these models are marked as invalid.
What changes are made to solve it?
References
openfga/openfga#2865
Review Checklist
mainSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.