---
id: w1/m17/t007
title: Test coverage — meaningful tests for recovery + lifecycle + access
worker: worker1
status: done
estimate: 30m
depends_on: [w1/m17/t005]
---

## Objective

The standing test-coverage pass: add meaningful tests for the three new capability groups — recovery (recovery-info/recover-to-new/exports), lifecycle (suspend/resume/restart), and access & connection (IP allowlist gating, pooler strings, users CRUD) — at the Core service level plus controller projection (envtest) and the relevant adapter shapes, so the DoD is enforced by tests, not just manually verified.

## Context

- Backend tests: `cd lego/backend && go test ./...`; operator controller tests use envtest via `make test` from `lego/operator/` (downloads envtest binaries first run).
- Test targets: `lego/backend/internal/postgres/` (Core verb + adapter tests) and `lego/operator/internal/controller/database_controller_test.go` (CNPG projection: backup config, hibernation annotation, `Pooler`, allowlist middleware, roles).
- Follow the existing table-driven / envtest patterns already in those packages; assert the Render-shaped response fields.
- New Go files carry the Apache-2.0 header from `lego/operator/hack/boilerplate.go.txt`.

## Steps

1. Core service tests: recovery-info/recover (restore-to-new, source untouched)/exports; suspend/resume/restart state transitions; ipAllowList set/read, pooler strings in connection-info, users CRUD (passwords never surfaced in logs/errors).
2. Controller (envtest) tests: the CNPG projections — `barmanObjectStore` + `ScheduledBackup`, hibernation annotation on suspend, `Pooler` creation, allowlist middleware/source-range, role provisioning.
3. Adapter-shape assertions where they add signal (Render-faithful JSON/GraphQL/MCP shapes).
4. Run `make test` (operator) + `go test ./...` (backend) green.

## Files

- `lego/backend/internal/postgres/*_test.go`
- `lego/operator/internal/controller/database_controller_test.go`

## Acceptance criteria

- [ ] Tests cover recovery (incl. restore-to-new leaving the source untouched), suspend/resume/restart, and IP allowlist + pooler + users.
- [ ] Controller envtests assert the CNPG projections (backup, hibernation, Pooler, allowlist, roles).
- [ ] `make test` (operator) + `go test ./...` (backend) green.

## Out of scope

- Live end-to-end restore against a real object store (envtest/unit-level here).
- HA / replica tests (deferred to `w1/013`).
