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

Function TestGaugeFunc

prometheus/gauge_test.go:164–194  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

162}
163
164func TestGaugeFunc(t *testing.T) {
165 gf := NewGaugeFunc(
166 GaugeOpts{
167 Name: "test_name",
168 Help: "test help",
169 ConstLabels: Labels{"a": "1", "b": "2"},
170 },
171 func() float64 { return 3.1415 },
172 )
173
174 if expected, got := `Desc{fqName: "test_name", help: "test help", constLabels: {a="1",b="2"}, variableLabels: {}}`, gf.Desc().String(); expected != got {
175 t.Errorf("expected %q, got %q", expected, got)
176 }
177
178 m := &dto.Metric{}
179 gf.Write(m)
180
181 expected := &dto.Metric{
182 Label: []*dto.LabelPair{
183 {Name: proto.String("a"), Value: proto.String("1")},
184 {Name: proto.String("b"), Value: proto.String("2")},
185 },
186 Gauge: &dto.Gauge{
187 Value: proto.Float64(3.1415),
188 },
189 }
190
191 if !proto.Equal(expected, m) {
192 t.Errorf("expected %q, got %q", expected, m)
193 }
194}
195
196func TestGaugeSetCurrentTime(t *testing.T) {
197 g := NewGauge(GaugeOpts{

Callers

nothing calls this directly

Calls 4

NewGaugeFuncFunction · 0.70
DescMethod · 0.65
WriteMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected