Engine And Factory
EngineFactory is the owner of shared test resources.
Key responsibilities:
- configure DB creation (
WithConnectionFactory) - apply engine extensions (
WithExtensions) - register factory-level providers (
RegisterFactoryProvider) - run factory close lifecycle (
Close)
Create once (commonly in TestMain) and reuse for all tests in the package.
Engine is created per test via factory.NewEngine(t).
It exposes:
BaseURL()for test HTTP server addressDB()/DBName()for SQL resourcesContext()for test-scoped contextExecute(t, runner)for runner executionSeed(...)andSeedWithProvider(...)for data setupTeardown()for resource cleanup
When NewEngine(t) is called:
- engine is initialized
- factory providers are bound into engine providers
- extensions run in order
t.Cleanupteardown is attached
On cleanup:
- DB-specific teardown (if configured by DB factory)
engine.Teardown()closes server/DB/providers
On factory close:
- factory close hooks run
- DB factory and factory providers are torn down
| |
This pattern matches the sqlite example.