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

Function TestCollectorFunc

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

Source from the content-addressed store, hash-verified

16import "testing"
17
18func TestCollectorFunc(t *testing.T) {
19 testDesc := NewDesc(
20 "test_metric",
21 "A test metric",
22 nil, nil,
23 )
24
25 cf := CollectorFunc(func(ch chan<- Metric) {
26 ch <- MustNewConstMetric(
27 testDesc,
28 GaugeValue,
29 42.0,
30 )
31 })
32
33 ch := make(chan Metric, 1)
34 cf.Collect(ch)
35 close(ch)
36
37 metric := <-ch
38 if metric == nil {
39 t.Fatal("Expected metric, got nil")
40 }
41
42 descCh := make(chan *Desc, 1)
43 cf.Describe(descCh)
44 close(descCh)
45
46 desc := <-descCh
47 if desc == nil {
48 t.Fatal("Expected desc, got nil")
49 }
50
51 if desc.String() != testDesc.String() {
52 t.Fatalf("Expected %s, got %s", testDesc.String(), desc.String())
53 }
54}
55
56func TestCollectorFuncWithRegistry(t *testing.T) {
57 reg := NewPedanticRegistry()

Callers

nothing calls this directly

Calls 6

StringMethod · 0.95
NewDescFunction · 0.85
CollectorFuncFuncType · 0.85
MustNewConstMetricFunction · 0.85
CollectMethod · 0.65
DescribeMethod · 0.65

Tested by

no test coverage detected