Testing
Andurel v2 reworks application testing around explicit constructors, storage.Connection, and isolated PostgreSQL databases.
Database tests
Use storage.NewTestCluster to start a shared PostgreSQL 17 Alpine container (via testcontainers) and create isolated databases per test. Prefer one cluster per package over a container per case.
1func TestMain(m *testing.M) {
2 ctx := context.Background()
3 cluster, err := storage.NewTestCluster(ctx)
4 if err != nil {
5 panic(err)
6 }
7 defer cluster.Close(ctx)
8
9 testCluster = cluster
10 os.Exit(m.Run())
11}
12
13func TestProductsCreate(t *testing.T) {
14 db := testCluster.NewTestDB(t, migrations.FS, "migrations")
15 product, err := factories.CreateProduct(ctx, db,
16 factories.WithProductName("Orbit"),
17 )
18 // ...
19}
NewTestDB creates a database, applies Goose migrations from an fs.FS, and registers cleanup. Generated projects embed SQL under root migrations/. See Getting Started.
Unit and HTTP tests
Construct collaborators through ordinary Go constructors or Fx test apps. Prefer fakes at interface boundaries (email senders, clocks) over global state.
Exercise Echo handlers with the same middleware stack the web process uses when behavior depends on kiks cookies or Inertia headers. Inject a real *kiks.Jar (or a focused test jar) rather than stuffing session values into ambient context.
Factories
Build entities with models/factories and keep them synchronized with the model Entity:
1andurel sync factories --check --json
1products, err := factories.CreateProducts(ctx, db, 3,
2 factories.WithProductActive(true),
3)
See Factories.