---
id: w3/m4/t006
title: "Test coverage — meaningful tests for the Prometheus resource source + fallback selection"
worker: worker3
status: done
estimate: 30m
depends_on: [w3/m4/t004]
---

## Objective

Add tests that assert the real behavior this milestone shipped: ranged queries produce stepped series, percentage mode divides by the actual pod limit, the `BEX_PROM_URL` toggle selects the right source, and failure modes (Prometheus unreachable, no source at all → 503) behave as documented. No tautological or snapshot-everything tests.

## Context

- Existing patterns: `operator/internal/api/metrics_test.go` fakes sources; the request-metrics tests already fake a Prometheus HTTP endpoint — mirror that for the resource source.

## Steps

1. Table-driven tests for `NewPrometheusResourceSource`: cpu/memory/instance_count mapping, range/step propagation into `query_range` params, label conventions.
2. Percentage-mode test with a known limit; error-path tests (bad Prometheus response, unreachable endpoint).
3. Selection test: source wiring with and without `BEX_PROM_URL`; 503 when unwired.

## Files

- `operator/internal/api/metrics_test.go` (or a sibling `metricsource_test.go`)

## Acceptance criteria

- [ ] Each shipped behavior above has a test that fails if the behavior regresses.
- [ ] `make test` green.

## Out of scope

- e2e/kind tests (`make test-e2e`).
