Skip to content

Add test helpers and infrastructure#717

Merged
morgo merged 2 commits into
block:mainfrom
morgo:test-helpers-infrastructure
Apr 30, 2026
Merged

Add test helpers and infrastructure#717
morgo merged 2 commits into
block:mainfrom
morgo:test-helpers-infrastructure

Conversation

@morgo
Copy link
Copy Markdown
Collaborator

@morgo morgo commented Apr 30, 2026

Summary

Fixes #718

Adds reusable test helpers to reduce boilerplate in migration tests. No existing test behavior is changed — this PR only:

  1. Adds new helper files
  2. Moves mkPtr, mkIniFile, waitForStatus to helpers_test.go (same package, no behavior change)
  3. Documents the helpers in AGENTS.md

New files

pkg/testutils/table.go — Table lifecycle management:

  • NewTestTable(t, name, createSQL) — creates table, registers cleanup for all Spirit artifacts
  • SeedRows(t, insertSelectSQL, targetRows) — populates via INSERT...SELECT doubling
  • TestTable.DB*sql.DB for verification queries

pkg/migration/helpers_test.go — Migration test helpers:

  • NewTestRunner(t, table, alter, opts...) — replaces ~15 lines of mysql.ParseDSN + NewRunner(&Migration{...})
  • NewTestRunnerFromStatement(t, stmt, opts...) — for CREATE INDEX, full ALTER TABLE, etc.
  • NewTestMigration(t, opts...) — for tests calling Migration.Run() directly
  • 12 With* option functions for configuration
  • Moved mkPtr, mkIniFile, waitForStatus from other test files

Tracking

Part of #716. Subsequent PRs will convert existing tests to use these helpers.

Add reusable test helpers to reduce boilerplate in migration tests:

pkg/testutils/table.go:
- NewTestTable: creates tables with automatic artifact cleanup
- SeedRows: populates tables via INSERT...SELECT doubling
- TestTable.DB: provides *sql.DB for verification queries

pkg/migration/helpers_test.go:
- NewTestRunner: creates Runner from table+alter with sensible defaults
- NewTestRunnerFromStatement: creates Runner from full SQL statement
- NewTestMigration: creates Migration struct for direct API testing
- With* options: WithThreads, WithBuffered, WithStatement, etc.
- Moved mkPtr, mkIniFile, waitForStatus from other test files

AGENTS.md:
- Documented all new helpers with examples and usage patterns
@morgo morgo force-pushed the test-helpers-infrastructure branch from eac436e to 4a361be Compare April 30, 2026 13:01
@morgo morgo requested a review from Copilot April 30, 2026 13:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds reusable helper utilities to simplify and standardize Spirit’s migration/integration tests as the first step of the broader migration test overhaul (#716).

Changes:

  • Added pkg/testutils.TestTable with lifecycle management (NewTestTable) and row seeding (SeedRows).
  • Added pkg/migration/helpers_test.go with migration/runner construction helpers and functional options; moved mkPtr, mkIniFile, and waitForStatus into this shared helper.
  • Documented the preferred test patterns and new helpers in AGENTS.md.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pkg/testutils/table.go New TestTable helper to create/cleanup Spirit tables and seed rows for integration tests.
pkg/migration/runner_test.go Removed local waitForStatus (moved to shared test helper).
pkg/migration/migration_test.go Removed local mkPtr/mkIniFile (moved to shared test helper).
pkg/migration/helpers_test.go New migration test helper constructors + functional options and shared utilities.
AGENTS.md Added documentation for NewTestTable/SeedRows and migration runner helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/testutils/table.go
Comment thread pkg/testutils/table.go Outdated
Comment thread pkg/testutils/table.go Outdated
Comment thread pkg/testutils/table.go
- Register t.Cleanup before createSQL so DB is always closed on failure
- Use context.Background() in cleanup drops (t.Context() is canceled)
- Use require.NoError in SeedRows loop to fail fast on insert errors
- Only ignore identifier-too-long errors in dropArtifacts, not all errors
@morgo morgo merged commit 664ba0f into block:main Apr 30, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1. Test helpers and infrastructure

3 participants