| 30 | ) |
| 31 | |
| 32 | func 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 |
| 39 | mf2 3 |
| 40 | mf1{label="value1"} -3.14 123456 |
| 41 | mf1{label="value2"} 42 |
| 42 | mf2 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 |