vigiloauth/vigilo

Refactor `vigilo_test_context.go` for improved readability and modularity

オープン

#354 opened on 2025/05/29

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)Go (9 件のフォーク)auto 404
good first issuerefactoringtesting

Repository metrics

Stars
 (100 個のスター)
PR merge metrics
 (PR metrics pending)

説明

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.

コントリビューターガイド