mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Start trying to write tests for promql
This commit is contained in:
parent
21cf437e8b
commit
fb03f9a388
|
@ -465,7 +465,7 @@ func (p *OpenMetricsParser) parseMetricSuffix(t token) (Entry, error) {
|
|||
if p.offsets[0] == -1 {
|
||||
return EntryInvalid, fmt.Errorf("metric name not set while parsing: %q", p.l.b[p.start:p.l.i])
|
||||
}
|
||||
|
||||
|
||||
var err error
|
||||
p.val, err = p.getFloatValue(t, "metric")
|
||||
if err != nil {
|
||||
|
@ -527,4 +527,4 @@ func (p *OpenMetricsParser) verifyMetricName(start, end int) error {
|
|||
return fmt.Errorf("metric name %q is not valid", m)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -473,6 +473,23 @@ var testExpr = []struct {
|
|||
StartPos: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
input: ` +{"some_metric"}`,
|
||||
expected: &UnaryExpr{
|
||||
Op: ADD,
|
||||
Expr: &VectorSelector{
|
||||
Name: "some_metric",
|
||||
LabelMatchers: []*labels.Matcher{
|
||||
MustLabelMatcher(labels.MatchEqual, model.MetricNameLabel, "some_metric"),
|
||||
},
|
||||
PosRange: posrange.PositionRange{
|
||||
Start: 2,
|
||||
End: 17,
|
||||
},
|
||||
},
|
||||
StartPos: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
input: "",
|
||||
fail: true,
|
||||
|
@ -1701,6 +1718,20 @@ var testExpr = []struct {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
input: `{"foo", a="bc"}`,
|
||||
expected: &VectorSelector{
|
||||
Name: "foo:bar",
|
||||
LabelMatchers: []*labels.Matcher{
|
||||
MustLabelMatcher(labels.MatchEqual, model.MetricNameLabel, "foo"),
|
||||
MustLabelMatcher(labels.MatchEqual, "a", "bc"),
|
||||
},
|
||||
PosRange: posrange.PositionRange{
|
||||
Start: 0,
|
||||
End: 15,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
input: `foo{NaN='bc'}`,
|
||||
expected: &VectorSelector{
|
||||
|
|
Loading…
Reference in a new issue