vigiloauth/vigilo

Refactor `vigilo_test_context.go` for improved readability and modularity

Aberta

#354 aberto em 29 de mai. de 2025

 (0 comentário) (0 reação) (0 responsável)Go (9 forks)auto 404
good first issuerefactoringtesting

Métricas do repositório

Stars
 (100 estrelas)
Métricas de merge de PR
 (Métricas PR pendentes)

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 WithClient by 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 VigiloTestContext are 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.

Guia do colaborador