Testing¶
Frame includes test utilities in frametests and tests to support integration and component tests.
What Exists¶
frametests/driver.go: test server driversframetests/testsuite.go: reusable test suitesframetests/deps: test dependencies (Postgres, NATS, Hydra, Keto, Valkey)
Strategy¶
- Use
frametestsutilities to spin up test dependencies. - Exercise
Service.Runwith a test driver or ephemeral ports. - Use
config.ConfigurationDefaultwith env overrides.
Example Pattern¶
ctx, svc := frame.NewService(
frame.WithName("test"),
frame.WithHTTPHandler(http.DefaultServeMux),
frametests.WithNoopDriver(), // or WithHTTPTestDriver() when you need httptest
)
defer svc.Stop(ctx)
// Test drivers return from ListenAndServe once ready (non-blocking).
// Run completes after startups finish — no goroutine required.
err := svc.Run(ctx, "")
require.NoError(t, err)
Tips¶
- Prefer integration tests for queue, cache, and datastore.
- Use
mem://drivers for fast unit tests. - Use
frametests.WithNoopDriver()when HTTP is not under test; useWithHTTPTestDriver()when you need a livehttptest.Server. - Do not wrap
svc.Runin a goroutine for test drivers — that is only needed for production-style drivers that block inListenAndServe.