package harness import ( "context" "testing" ) // NotificationServicePersistence captures the per-test persistence // dependencies of the Notification Service binary: a PostgreSQL container // hosting the `notification` schema owned by the `notificationservice` role, // and the Redis credentials that point the service at the caller-supplied // master address. type NotificationServicePersistence struct { // Postgres exposes the started container so tests that need direct SQL // access to the notification 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 // notification-service process. It is safe to merge into the caller's // existing env map, or to use as-is and append further NOTIFICATION_* // knobs in place. Env map[string]string } // StartNotificationServicePersistence brings up one isolated PostgreSQL // container, provisions the `notification` schema with the // `notificationservice` role, and returns the environment entries that wire // the notification-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 StartNotificationServicePersistence(t testing.TB, redisMasterAddr string) NotificationServicePersistence { t.Helper() rt := StartPostgresContainer(t) if err := rt.EnsureRoleAndSchema(context.Background(), "notification", "notificationservice", "notificationservice"); err != nil { t.Fatalf("ensure notification schema/role: %v", err) } env := WithPostgres(rt, "NOTIFICATION", "notification", "notificationservice") env["NOTIFICATION_REDIS_MASTER_ADDR"] = redisMasterAddr env["NOTIFICATION_REDIS_PASSWORD"] = "integration" return NotificationServicePersistence{ Postgres: rt, Env: env, } }