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

Function TestCollectAndFormat

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

Source from the content-addressed store, hash-verified

435}
436
437func TestCollectAndFormat(t *testing.T) {
438 const expected = `# HELP foo_bar A value that represents the number of bars in foo.
439# TYPE foo_bar counter
440foo_bar{fizz="bang"} 1
441`
442 c := prometheus.NewCounterVec(
443 prometheus.CounterOpts{
444 Name: "foo_bar",
445 Help: "A value that represents the number of bars in foo.",
446 },
447 []string{"fizz"},
448 )
449 c.WithLabelValues("bang").Inc()
450
451 got, err := CollectAndFormat(c, expfmt.TypeTextPlain, "foo_bar")
452 if err != nil {
453 t.Errorf("unexpected error: %s", err.Error())
454 }
455
456 gotS := string(got)
457 if err != nil {
458 t.Errorf("unexpected error: %s", err.Error())
459 }
460
461 if gotS != expected {
462 t.Errorf("unexpected metric output, got %q, expected %q", gotS, expected)
463 }
464}

Callers

nothing calls this directly

Calls 5

WithLabelValuesMethod · 0.95
NewCounterVecFunction · 0.92
CollectAndFormatFunction · 0.85
IncMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected