vigiloauth/vigilo
Refactor `vigilo_test_context.go` for improved readability and modularity
Ouverte
#354 ouverte le 29 mai 2025
good first issuerefactoringtesting
Métriques du dépôt
- Stars
- (100 étoiles)
- Métriques de merge PR
- (Métriques PR en attente)
Description
Description:
The vigilo_test_context.go file currently contains a large test context struct and many helper methods used across integration tests. While functional, the file has become quite large and complex, making it harder to maintain and extend.
Goals of the refactor:
- Improve code readability by splitting concerns into smaller, focused methods or helper structs.
- Group related methods and constants logically (e.g., user creation, client setup, JWT token generation).
- Remove redundant or repeated code patterns by introducing reusable private helper functions.
- Ensure the test context can be extended easily with minimal code duplication.
- Add or improve documentation/comments for public and internal methods.
- Make error handling more consistent and clear within test setup steps.
Suggested steps:
- Extract user creation logic to a dedicated private method or helper.
- Group JWT token creation variants (
WithJWTToken,WithAdminToken,WithJWTTokenWithScopes, etc.) to reuse common token creation code. - Simplify
WithClientby splitting configuration setup from saving the client. - Isolate constants into a dedicated section or even a separate file if appropriate.
- Add more consistent error assertions (require.NoError) where missing.
- Ensure all fields in
VigiloTestContextare initialized properly and consistently. - Possibly add builder patterns or configuration structs to reduce method parameters.
Benefits:
- Easier onboarding for new contributors.
- Reduced likelihood of bugs caused by setup inconsistencies.
- Easier to add new test features and helper methods.
- Improved maintainability and clarity of integration tests.