MCPcopy
hub / github.com/prometheus/client_golang / TestCollectorFuncWithRegistry

Function TestCollectorFuncWithRegistry

prometheus/collectorfunc_test.go:56–83  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

54}
55
56func TestCollectorFuncWithRegistry(t *testing.T) {
57 reg := NewPedanticRegistry()
58
59 cf := CollectorFunc(func(ch chan<- Metric) {
60 ch <- MustNewConstMetric(
61 NewDesc(
62 "test_metric",
63 "A test metric",
64 nil, nil,
65 ),
66 GaugeValue,
67 42.0,
68 )
69 })
70
71 if err := reg.Register(cf); err != nil {
72 t.Errorf("Failed to register CollectorFunc: %v", err)
73 }
74
75 collectedMetrics, err := reg.Gather()
76 if err != nil {
77 t.Errorf("Failed to gather metrics: %v", err)
78 }
79
80 if len(collectedMetrics) != 1 {
81 t.Errorf("Expected 1 metric family, got %d", len(collectedMetrics))
82 }
83}

Callers

nothing calls this directly

Calls 6

NewPedanticRegistryFunction · 0.85
CollectorFuncFuncType · 0.85
MustNewConstMetricFunction · 0.85
NewDescFunction · 0.85
RegisterMethod · 0.65
GatherMethod · 0.65

Tested by

no test coverage detected