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

Function TestCollectAndCompare

prometheus/testutil/testutil_test.go:126–149  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

124}
125
126func TestCollectAndCompare(t *testing.T) {
127 const metadata = `
128 # HELP some_total A value that represents a counter.
129 # TYPE some_total counter
130 `
131
132 c := prometheus.NewCounter(prometheus.CounterOpts{
133 Name: "some_total",
134 Help: "A value that represents a counter.",
135 ConstLabels: prometheus.Labels{
136 "label1": "value1",
137 },
138 })
139 c.Inc()
140
141 expected := `
142
143 some_total{ label1 = "value1" } 1
144 `
145
146 if err := CollectAndCompare(c, strings.NewReader(metadata+expected), "some_total"); err != nil {
147 t.Errorf("unexpected collecting result:\n%s", err)
148 }
149}
150
151func TestCollectAndCompareNoLabel(t *testing.T) {
152 const metadata = `

Callers

nothing calls this directly

Calls 3

IncMethod · 0.95
NewCounterFunction · 0.92
CollectAndCompareFunction · 0.85

Tested by

no test coverage detected