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

Function TestNewConstMetricInvalidLabelValues

prometheus/value_test.go:24–59  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func TestNewConstMetricInvalidLabelValues(t *testing.T) {
25 testCases := []struct {
26 desc string
27 labels Labels
28 }{
29 {
30 desc: "non utf8 label value",
31 labels: Labels{"a": "\xFF"},
32 },
33 {
34 desc: "not enough label values",
35 labels: Labels{},
36 },
37 {
38 desc: "too many label values",
39 labels: Labels{"a": "1", "b": "2"},
40 },
41 }
42
43 for _, test := range testCases {
44 metricDesc := NewDesc(
45 "sample_value",
46 "sample value",
47 []string{"a"},
48 Labels{},
49 )
50
51 expectPanic(t, func() {
52 MustNewConstMetric(metricDesc, CounterValue, 0.3, "\xFF")
53 }, "WithLabelValues: expected panic because: "+test.desc)
54
55 if _, err := NewConstMetric(metricDesc, CounterValue, 0.3, "\xFF"); err == nil {
56 t.Errorf("NewConstMetric: expected error because: %s", test.desc)
57 }
58 }
59}
60
61func TestNewConstMetricWithCreatedTimestamp(t *testing.T) {
62 now := time.Now()

Callers

nothing calls this directly

Calls 4

NewDescFunction · 0.85
expectPanicFunction · 0.85
MustNewConstMetricFunction · 0.85
NewConstMetricFunction · 0.85

Tested by

no test coverage detected