ProofedMesh/services/attest-reconciler/internal/metrics/metrics_test.go
CTO 2e44147a71
All checks were successful
validate / JSON Schema (ajv) (push) Successful in 19s
validate / Go (vet + test) (push) Successful in 19s
validate / Rego (opa fmt + opa test) (push) Successful in 14s
services: add attest-reconciler Go service (periodic worker re-signs per_diem_rates rows without rate_change_attestation_ref via Signer+TLog, 11/11 go tests pass, go vet clean)
- services/attest-reconciler/ as its own go.mod (admin-api internal/ is not importable; shared code gets extracted when a 3rd consumer appears).
- Scheduler accepts "@every <dur>" or a bare Go duration; context-cancellation stops the loop cleanly.
- Store client defines PendingRateStore + Postgres skeleton for SELECT ... WHERE rate_change_attestation_ref IS NULL.
- Orchestrator + HTTPSigner + tlog.HTTPSubmitter mirror admin-api byte-for-byte so the TLog idempotency key collides on resubmits (kein Doppelsignieren).
- Prometheus text-format /metrics endpoint, dependency-free: attest_reconciler_dirty_rows_total, _reconciliation_attempts_total, _reconciliation_failures_total, _idempotent_noop_total.
- Tests with fake store + fake signer + fake submitter cover: happy path, already-attested rows are NOT re-signed, TLog idempotency across ticks, TLog-down failure path, pre-cancelled ctx.
- Top-level README reflects the new service; CI auto-discovers services/*/go.mod so no workflow change needed.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-10-25 18:06:36 +00:00

38 lines
991 B
Go

package metrics
import (
"net/http/httptest"
"strings"
"testing"
)
func TestRegistrySnapshotAndTextFormat(t *testing.T) {
r := New()
r.SetDirtyRows(7)
r.IncAttempts()
r.IncAttempts()
r.IncAttempts()
r.IncFailures()
r.IncIdempotentNoopHits()
snap := r.Snapshot()
if snap.DirtyRows != 7 || snap.ReconciliationAttempts != 3 || snap.ReconciliationFailures != 1 || snap.IdempotentNoopHits != 1 {
t.Fatalf("unexpected snapshot: %+v", snap)
}
req := httptest.NewRequest("GET", "/metrics", nil)
w := httptest.NewRecorder()
r.Handler().ServeHTTP(w, req)
body := w.Body.String()
for _, substr := range []string{
"attest_reconciler_dirty_rows_total 7",
"attest_reconciler_reconciliation_attempts_total 3",
"attest_reconciler_reconciliation_failures_total 1",
"attest_reconciler_idempotent_noop_total 1",
"# TYPE attest_reconciler_dirty_rows_total gauge",
} {
if !strings.Contains(body, substr) {
t.Errorf("metrics output missing %q:\n%s", substr, body)
}
}
}