ProofedMesh/services/attest-reconciler/internal/metrics/metrics_test.go

39 lines
991 B
Go
Raw Normal View History

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)
}
}
}