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

Function TestCollectAndCount

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

Source from the content-addressed store, hash-verified

408}
409
410func TestCollectAndCount(t *testing.T) {
411 c := prometheus.NewCounterVec(
412 prometheus.CounterOpts{
413 Name: "some_total",
414 Help: "A value that represents a counter.",
415 },
416 []string{"foo"},
417 )
418 if got, want := CollectAndCount(c), 0; got != want {
419 t.Errorf("unexpected metric count, got %d, want %d", got, want)
420 }
421 c.WithLabelValues("bar")
422 if got, want := CollectAndCount(c), 1; got != want {
423 t.Errorf("unexpected metric count, got %d, want %d", got, want)
424 }
425 c.WithLabelValues("baz")
426 if got, want := CollectAndCount(c), 2; got != want {
427 t.Errorf("unexpected metric count, got %d, want %d", got, want)
428 }
429 if got, want := CollectAndCount(c, "some_total"), 2; got != want {
430 t.Errorf("unexpected metric count, got %d, want %d", got, want)
431 }
432 if got, want := CollectAndCount(c, "some_other_total"), 0; got != want {
433 t.Errorf("unexpected metric count, got %d, want %d", got, want)
434 }
435}
436
437func TestCollectAndFormat(t *testing.T) {
438 const expected = `# HELP foo_bar A value that represents the number of bars in foo.

Callers

nothing calls this directly

Calls 3

WithLabelValuesMethod · 0.95
NewCounterVecFunction · 0.92
CollectAndCountFunction · 0.85

Tested by

no test coverage detected