52 lines
2.0 KiB
Go
52 lines
2.0 KiB
Go
package harness
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
// LobbyServicePersistence captures the per-test persistence dependencies of
|
|
// the Game Lobby Service binary: a PostgreSQL container hosting the `lobby`
|
|
// schema owned by the `lobbyservice` role, plus the Redis credentials that
|
|
// point the service at the caller-supplied master address.
|
|
type LobbyServicePersistence struct {
|
|
// Postgres exposes the started container so tests that need direct SQL
|
|
// access to the lobby 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
|
|
// lobby-service process. It is safe to merge into the caller's existing
|
|
// env map, or to use as-is and append further LOBBY_* knobs in place.
|
|
Env map[string]string
|
|
}
|
|
|
|
// StartLobbyServicePersistence brings up one isolated PostgreSQL container,
|
|
// provisions the `lobby` schema with the `lobbyservice` role, and returns
|
|
// the environment entries that wire the lobby-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 StartPostgresContainer through
|
|
// `t.Cleanup`; callers do not need to defer anything.
|
|
func StartLobbyServicePersistence(t testing.TB, redisMasterAddr string) LobbyServicePersistence {
|
|
t.Helper()
|
|
|
|
rt := StartPostgresContainer(t)
|
|
if err := rt.EnsureRoleAndSchema(context.Background(), "lobby", "lobbyservice", "lobbyservice"); err != nil {
|
|
t.Fatalf("ensure lobby schema/role: %v", err)
|
|
}
|
|
|
|
env := WithPostgres(rt, "LOBBY", "lobby", "lobbyservice")
|
|
env["LOBBY_REDIS_MASTER_ADDR"] = redisMasterAddr
|
|
env["LOBBY_REDIS_PASSWORD"] = "integration"
|
|
return LobbyServicePersistence{
|
|
Postgres: rt,
|
|
Env: env,
|
|
}
|
|
}
|