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

Function TestToFloat64

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

Source from the content-addressed store, hash-verified

40}
41
42func TestToFloat64(t *testing.T) {
43 gaugeWithAValueSet := prometheus.NewGauge(prometheus.GaugeOpts{})
44 gaugeWithAValueSet.Set(3.14)
45
46 counterVecWithOneElement := prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"foo"})
47 counterVecWithOneElement.WithLabelValues("bar").Inc()
48
49 counterVecWithTwoElements := prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"foo"})
50 counterVecWithTwoElements.WithLabelValues("bar").Add(42)
51 counterVecWithTwoElements.WithLabelValues("baz").Inc()
52
53 histogramVecWithOneElement := prometheus.NewHistogramVec(prometheus.HistogramOpts{}, []string{"foo"})
54 histogramVecWithOneElement.WithLabelValues("bar").Observe(2.7)
55
56 scenarios := map[string]struct {
57 collector prometheus.Collector
58 panics bool
59 want float64
60 }{
61 "simple counter": {
62 collector: prometheus.NewCounter(prometheus.CounterOpts{}),
63 panics: false,
64 want: 0,
65 },
66 "simple gauge": {
67 collector: prometheus.NewGauge(prometheus.GaugeOpts{}),
68 panics: false,
69 want: 0,
70 },
71 "simple untyped": {
72 collector: untypedCollector{},
73 panics: false,
74 want: 2001,
75 },
76 "simple histogram": {
77 collector: prometheus.NewHistogram(prometheus.HistogramOpts{}),
78 panics: true,
79 },
80 "simple summary": {
81 collector: prometheus.NewSummary(prometheus.SummaryOpts{}),
82 panics: true,
83 },
84 "simple gauge with an actual value set": {
85 collector: gaugeWithAValueSet,
86 panics: false,
87 want: 3.14,
88 },
89 "counter vec with zero elements": {
90 collector: prometheus.NewCounterVec(prometheus.CounterOpts{}, nil),
91 panics: true,
92 },
93 "counter vec with one element": {
94 collector: counterVecWithOneElement,
95 panics: false,
96 want: 1,
97 },
98 "counter vec with two elements": {
99 collector: counterVecWithTwoElements,

Callers

nothing calls this directly

Calls 15

SetMethod · 0.95
WithLabelValuesMethod · 0.95
WithLabelValuesMethod · 0.95
NewGaugeFunction · 0.92
NewCounterVecFunction · 0.92
NewHistogramVecFunction · 0.92
NewCounterFunction · 0.92
NewHistogramFunction · 0.92
NewSummaryFunction · 0.92
ToFloat64Function · 0.85
RunMethod · 0.80
IncMethod · 0.65

Tested by

no test coverage detected