package metrics import ( "net/http/httptest" "strings" "testing" "time" "github.com/prometheus/client_golang/prometheus/testutil" ) func TestMetricsRecord(t *testing.T) { m := New() m.ObserveCheck("drift", 100*time.Millisecond) m.ObserveCheck("in_sync", 50*time.Millisecond) m.IncNotification("telegram", "ok") m.SetDrift(3) if got := testutil.ToFloat64(m.ChecksTotal.WithLabelValues("drift")); got != 1 { t.Fatalf("checks drift = %v", got) } if got := testutil.ToFloat64(m.DriftDomains); got != 3 { t.Fatalf("drift gauge = %v", got) } if got := testutil.ToFloat64(m.NotificationsTotal.WithLabelValues("telegram", "ok")); got != 1 { t.Fatalf("notif = %v", got) } } func TestHandlerExposesMetrics(t *testing.T) { m := New() m.ObserveCheck("in_sync", time.Millisecond) rec := httptest.NewRecorder() m.Handler().ServeHTTP(rec, httptest.NewRequest("GET", "/metrics", nil)) if rec.Code != 200 || !strings.Contains(rec.Body.String(), "dns_ar_checks_total") { t.Fatalf("metrics not exposed: %d", rec.Code) } }