MCPcopy Create free account
hub / github.com/prometheus/common / TestTextDecoder

Function TestTextDecoder

expfmt/decode_test.go:32–101  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30)
31
32func TestTextDecoder(t *testing.T) {
33 var (
34 ts = model.Now()
35 in = `
36# Only a quite simple scenario with two metric families.
37# More complicated tests of the parser itself can be found in the text package.
38# TYPE mf2 counter
39mf2 3
40mf1{label="value1"} -3.14 123456
41mf1{label="value2"} 42
42mf2 4
43`
44 out = model.Vector{
45 &model.Sample{
46 Metric: model.Metric{
47 model.MetricNameLabel: "mf1",
48 "label": "value1",
49 },
50 Value: -3.14,
51 Timestamp: 123456,
52 },
53 &model.Sample{
54 Metric: model.Metric{
55 model.MetricNameLabel: "mf1",
56 "label": "value2",
57 },
58 Value: 42,
59 Timestamp: ts,
60 },
61 &model.Sample{
62 Metric: model.Metric{
63 model.MetricNameLabel: "mf2",
64 },
65 Value: 3,
66 Timestamp: ts,
67 },
68 &model.Sample{
69 Metric: model.Metric{
70 model.MetricNameLabel: "mf2",
71 },
72 Value: 4,
73 Timestamp: ts,
74 },
75 }
76 )
77
78 dec := &SampleDecoder{
79 Dec: &textDecoder{r: strings.NewReader(in)},
80 Opts: &DecodeOptions{
81 Timestamp: ts,
82 },
83 }
84 var all model.Vector
85 for {
86 var smpls model.Vector
87 err := dec.Decode(&smpls)
88 if err != nil && errors.Is(err, io.EOF) {
89 break

Callers

nothing calls this directly

Calls 2

DecodeMethod · 0.95
NowFunction · 0.92

Tested by

no test coverage detected