55 lines
2.1 KiB
Go
55 lines
2.1 KiB
Go
package harness
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
// RTManagerServicePersistence captures the per-test persistence
|
|
// dependencies of the Runtime Manager binary: a PostgreSQL container
|
|
// hosting the `rtmanager` schema owned by the `rtmanagerservice` role,
|
|
// plus the Redis credentials that point the service at the
|
|
// caller-supplied master address.
|
|
type RTManagerServicePersistence struct {
|
|
// Postgres exposes the started container so tests that need direct
|
|
// SQL access to the rtmanager schema can read or write through it.
|
|
Postgres *PostgresRuntime
|
|
|
|
// Env carries the environment entries that must be passed to the
|
|
// rtmanager process. It is safe to merge into the caller's existing
|
|
// env map, or to use as-is and append further RTMANAGER_* knobs in
|
|
// place. RTMANAGER_GAME_STATE_ROOT is intentionally omitted; the
|
|
// caller supplies a per-test directory.
|
|
Env map[string]string
|
|
}
|
|
|
|
// StartRTManagerServicePersistence brings up one isolated PostgreSQL
|
|
// container, provisions the `rtmanager` schema with the
|
|
// `rtmanagerservice` role, and returns the environment entries that
|
|
// wire the rtmanager binary at that container plus the supplied Redis
|
|
// master address.
|
|
//
|
|
// The Redis password value matches the architectural rule that Redis
|
|
// traffic is password-protected; miniredis accepts arbitrary password
|
|
// values when its own RequireAuth is not engaged, and the same value
|
|
// works against the real testcontainers Redis runtime.
|
|
//
|
|
// Cleanup of the container is handled by StartPostgresContainer through
|
|
// `t.Cleanup`; callers do not need to defer anything.
|
|
func StartRTManagerServicePersistence(t testing.TB, redisMasterAddr string) RTManagerServicePersistence {
|
|
t.Helper()
|
|
|
|
rt := StartPostgresContainer(t)
|
|
if err := rt.EnsureRoleAndSchema(context.Background(), "rtmanager", "rtmanagerservice", "rtmanagerservice"); err != nil {
|
|
t.Fatalf("ensure rtmanager schema/role: %v", err)
|
|
}
|
|
|
|
env := WithPostgres(rt, "RTMANAGER", "rtmanager", "rtmanagerservice")
|
|
env["RTMANAGER_REDIS_MASTER_ADDR"] = redisMasterAddr
|
|
env["RTMANAGER_REDIS_PASSWORD"] = "integration"
|
|
return RTManagerServicePersistence{
|
|
Postgres: rt,
|
|
Env: env,
|
|
}
|
|
}
|