vigiloauth/vigilo

Refactor `vigilo_test_context.go` for improved readability and modularity

开放

#354 创建于 2025年5月29日

 (0 条评论) (0 个反应) (0 位负责人)Go (9 个派生)auto 404
good first issuerefactoringtesting

仓库指标

星标
 (100 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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.

贡献者指南