feat: use postgres
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package harness
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// MailServicePersistence captures the per-test persistence dependencies of
|
||||
// the Mail Service binary: a PostgreSQL container hosting the `mail` schema
|
||||
// owned by the `mailservice` role, and the Redis credentials that point the
|
||||
// service at the caller-supplied master address.
|
||||
type MailServicePersistence struct {
|
||||
// Postgres exposes the started container so tests that need direct SQL
|
||||
// access to the mail schema (verifying side effects, seeding fixtures)
|
||||
// can read or write through it.
|
||||
Postgres *PostgresRuntime
|
||||
|
||||
// Env carries the environment entries that must be passed to the
|
||||
// mail-service process. It is safe to merge into the caller's existing env
|
||||
// map, or to use as-is and append further MAIL_* knobs in place.
|
||||
Env map[string]string
|
||||
}
|
||||
|
||||
// StartMailServicePersistence brings up one isolated PostgreSQL container,
|
||||
// provisions the `mail` schema with the `mailservice` role, and returns the
|
||||
// environment entries that wire the mail-service binary at that container plus
|
||||
// the supplied Redis master address.
|
||||
//
|
||||
// The returned password (`integration`) matches the architectural rule that
|
||||
// Redis traffic is password-protected; miniredis accepts arbitrary password
|
||||
// values when its own RequireAuth is not engaged, so the same value works
|
||||
// against both miniredis and the real `tcredis` runtime.
|
||||
//
|
||||
// Cleanup of the container is handled by the underlying StartPostgresContainer
|
||||
// through `t.Cleanup`; callers do not need to defer anything.
|
||||
func StartMailServicePersistence(t testing.TB, redisMasterAddr string) MailServicePersistence {
|
||||
t.Helper()
|
||||
|
||||
rt := StartPostgresContainer(t)
|
||||
if err := rt.EnsureRoleAndSchema(context.Background(), "mail", "mailservice", "mailservice"); err != nil {
|
||||
t.Fatalf("ensure mail schema/role: %v", err)
|
||||
}
|
||||
|
||||
env := WithPostgres(rt, "MAIL", "mail", "mailservice")
|
||||
env["MAIL_REDIS_MASTER_ADDR"] = redisMasterAddr
|
||||
env["MAIL_REDIS_PASSWORD"] = "integration"
|
||||
return MailServicePersistence{
|
||||
Postgres: rt,
|
||||
Env: env,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user