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