---
id: w1/m14/t005
title: Test coverage — envtest for the `KeyValue` reconciler
worker: worker1
status: done
estimate: 30m
depends_on: [w1/m14/t003]
---

## Objective

Add envtest coverage for the `KeyValue` reconciler proving the mechanism end to end at the controller level: creating a CR yields the workload + Service + Secret; the tier maps to the expected resources; and deleting the CR cascades the owned objects away. Mirror the existing `Database` controller tests.

## Context

- `lego/operator/internal/controller/database_test.go` and `tier_resources_test.go` — the analogs to copy: they stand up the reconciler against the envtest apiserver, apply a CR, and assert the projected objects + tier→resources mapping. New file: `lego/operator/internal/controller/keyvalue_test.go`.
- `suite_test.go` — the shared envtest suite (scheme registration, `envtest.Environment`); ensure the `KeyValue` type is registered there.
- `make test` (run from `lego/operator/`) runs codegen then unit + envtest; envtest binaries download to `bin/` on first run.
- Delete cascade is enforced by the owner references set in t002/t003 — assert the workload, Service, Secret (and public route, when configured) are garbage-collected after the CR is deleted.

## Steps

1. Add `lego/operator/internal/controller/keyvalue_test.go`: CR create → assert Valkey workload + ClusterIP Service + password Secret exist and are owner-referenced.
2. Assert tier → resources: a given tier produces the expected `requests==limits` + storage (mirror `tier_resources_test.go`).
3. Assert delete cascade: deleting the `KeyValue` removes the owned objects.
4. Register the type in `suite_test.go` if needed; run `make test` from `lego/operator/` and confirm green.

## Files

- `lego/operator/internal/controller/keyvalue_test.go` (new)
- `lego/operator/internal/controller/suite_test.go` (register the type if needed)

## Acceptance criteria

- [ ] envtest covers CR create → workload + Service + Secret present and owner-referenced.
- [ ] A tier→resources assertion verifies compute + storage for at least one tier.
- [ ] A delete-cascade assertion verifies the owned objects are removed when the CR is deleted.
- [ ] `make test` (from `lego/operator/`) is green including the new reconciler test.

## Out of scope

- Any REST/GraphQL/MCP/dashboard-level tests (those surfaces are deferred to w2/w5).
- e2e (`make test-e2e`) — envtest only.
