-
Notifications
You must be signed in to change notification settings - Fork 140
auth test: refactor for better error #7814
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
Conversation
Refactor tests in prep for CBG-4345 which changes some return values. - create helper functions - replace assert.True(t, x == y) with assert.Equal(t, x, y) - Create error types to assert on
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.
Pull Request Overview
Refactors authentication test code to prepare for CBG-4345 by improving error handling and test assertions. Key changes include creating structured error types for authorization failures, replacing loose boolean assertions with specific error checking, and introducing helper functions to reduce code duplication.
- Create standardized error types for different authorization failure scenarios
- Replace
assert.True(t, x == y)patterns withassert.Equal(t, x, y)for better error messages - Add helper functions to reduce repetitive test code and improve readability
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| auth/error.go | New file defining structured error types and helper functions for authorization failures |
| auth/principal.go | Update UnauthError interface to accept error instead of string |
| auth/role.go | Implement new UnauthError signature and use structured errors |
| auth/user_collection_access.go | Use new structured error types |
| auth/role_collection_access.go | Use new structured error types and remove unused imports |
| db/functions.go | Use structured error with HTTP status code |
| db/functions/function.go | Use structured error with HTTP status code |
| auth/collection_access_test.go | Add helper functions and improve test assertions |
| auth/auth_test.go | Add helper functions and improve test assertions |
Co-authored-by: Copilot <[email protected]>
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.
LGTM generally. Approved as can be merged as is and nit picks could be picked up in your follow up PR
Refactor tests in prep for CBG-4345 which changes some return values.
This change will make the bulk of CBG-4345 less onerous to read since it will add err to several functions that are used like
canSeeChannelandexpandWildCardChanneland that would split cause a lot of changes to these test files.Pre-review checklist
fmt.Print,log.Print, ...)base.UD(docID),base.MD(dbName))docs/apiIntegration Tests
GSI=true,xattrs=truehttps://jenkins.sgwdev.com/job/SyncGatewayIntegration/135/