Skip to content

Standardize Tester Constructor Pattern Across Shared Library #11

@chendingplano

Description

@chendingplano

Issue: Standardize Tester Constructor Pattern Across Shared Library

Summary

The shared library tester registration and constructors have been updated to use a uniform no-argument pattern. All testers now follow the same construction approach with proper database initialization in their Prepare() methods.

Problem

The previous implementation had inconsistencies:

  1. Inconsistent constructor signatures: Some testers accepted optional config parameters (*DBConfig, *MigrationTesterConfig), while others took no parameters
  2. Unused config fields: The dbConfig field in DatabaseTester was never used - the database connection was always obtained from ApiTypes.PG_DB_Project in Prepare()
  3. Non-uniform pattern: Different testers used different initialization approaches, making the codebase harder to maintain

Solution

Standardized all shared library testers to follow a uniform no-argument constructor pattern:

  1. No-argument constructors: All testers now use NewTesterName() with no parameters
  2. Proper DB initialization in Prepare(): Each tester's Prepare() method obtains the database connection from ApiTypes.PG_DB_Project and verifies it
  3. Consistent pattern: All testers (shared and application-specific) now follow the same construction pattern

Files Changed

api/testers/registertesters.go

  • Updated all factory calls to use no-argument pattern:
    • NewDatabaseTester() instead of NewDatabaseTester(nil)
    • NewMigrationTester() instead of NewMigrationTester(nil)
  • Fixed documentation comment: autotester.LoadTOMLPackages() instead of sharedtesters.LoadTOMLPackages()

api/testers/tester_database.go

  • Removed dbConfig *ApiTypes.DBConfig field from DatabaseTester struct (was unused)
  • Changed NewDatabaseTester(dbConfig *ApiTypes.DBConfig) to NewDatabaseTester()
  • Prepare() already properly initializes testDB from ApiTypes.PG_DB_Project

api/testers/tester-migration/tester_migration.go

  • Changed NewMigrationTester(cfg *MigrationTesterConfig) to NewMigrationTester()
  • Constructor now always creates default config internally with cfg.ApplyDefaults()
  • Maintains same behavior but with cleaner API

Testing

  • Build verified: go build ./shared/go/... completes successfully
  • All workspace modules build successfully:
    • shared/go/...
    • tax/server/...
    • ChenWeb/...
    • Ory/backend/...

Impact

  • Improves: API consistency across all testers
  • Simplifies: Tester registration - no need to pass nil or config parameters
  • Removes: Unused dbConfig field from DatabaseTester
  • Aligns: Shared library testers with application-specific testers (tax project)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions