---
id: w1/m22/t008
title: Test coverage — HA reconcile + failover + replica URL tests
worker: worker1
status: todo
estimate: 40m
depends_on: [w1/m22/t006]
---

## Objective

Add meaningful tests for the HA behavior: the replicated-cluster reconcile, the failover/promote path, replica URL issuance + read-only enforcement, and the API surface. Assert real behavior and failure modes.

## Context

- Operator: HA `Database` → ≥2-instance CNPG cluster; non-HA unchanged; failover promotes a standby; replica URL is read-only.
- Backend: HA enable/failover/replica-URL round-trip + `highAvailabilityEnabled` truthfulness.

## Steps

1. Envtest the HA reconcile (instance count, replication, anti-affinity) and the single-instance no-change guard.
2. Test the failover action (primary changes; `-rw` follows) as far as envtest/integration allows.
3. Test replica URL construction + external-hostname gating; backend surface tests.

## Files

- `lego/operator/…_test.go`, `lego/backend/…_test.go`

## Acceptance criteria

- [ ] Tests fail if HA silently degrades to single-instance, or if `highAvailabilityEnabled` desyncs from the CR.
- [ ] `make test` + backend `go test ./...` green.

## Out of scope

- Non-HA behavior.
