feat: use postgres
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package harness
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// UserServicePersistence captures the per-test persistence dependencies of
|
||||
// the User Service binary: a PostgreSQL container hosting the `user` schema
|
||||
// owned by the `userservice` role, and the Redis credentials that point the
|
||||
// service at the caller-supplied master address.
|
||||
type UserServicePersistence struct {
|
||||
// Postgres exposes the started container so tests that need direct SQL
|
||||
// access to the user 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
|
||||
// userservice process. It is safe to merge into the caller's existing env
|
||||
// map, or to use as-is and append further USERSERVICE_* knobs in place.
|
||||
Env map[string]string
|
||||
}
|
||||
|
||||
// StartUserServicePersistence brings up one isolated PostgreSQL container,
|
||||
// provisions the `user` schema with the `userservice` role, and returns the
|
||||
// environment entries that wire the userservice 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 StartUserServicePersistence(t testing.TB, redisMasterAddr string) UserServicePersistence {
|
||||
t.Helper()
|
||||
|
||||
rt := StartPostgresContainer(t)
|
||||
if err := rt.EnsureRoleAndSchema(context.Background(), "user", "userservice", "userservice"); err != nil {
|
||||
t.Fatalf("ensure user schema/role: %v", err)
|
||||
}
|
||||
|
||||
env := WithPostgres(rt, "USERSERVICE", "user", "userservice")
|
||||
env["USERSERVICE_REDIS_MASTER_ADDR"] = redisMasterAddr
|
||||
env["USERSERVICE_REDIS_PASSWORD"] = "integration"
|
||||
return UserServicePersistence{
|
||||
Postgres: rt,
|
||||
Env: env,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user