Merge pull request #1778 from mattbostock/fix_annotations

promql: Fix annotations conflated with labels
pull/1780/head
Fabian Reinartz 2016-07-01 11:45:18 +02:00 committed by GitHub
commit 4d1985e405
1 changed files with 35 additions and 0 deletions

View File

@ -15,8 +15,43 @@ package promql
import (
"testing"
"time"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/storage/metric"
)
func TestStatementString(t *testing.T) {
in := &AlertStmt{
Name: "FooAlert",
Expr: &BinaryExpr{
Op: itemGTR,
LHS: &VectorSelector{
Name: "foo",
LabelMatchers: metric.LabelMatchers{
{Type: metric.Equal, Name: model.MetricNameLabel, Value: "bar"},
},
},
RHS: &NumberLiteral{10},
},
Duration: 5 * time.Minute,
Labels: model.LabelSet{"foo": "bar"},
Annotations: model.LabelSet{
"notify": "team-a",
},
}
expected := `ALERT FooAlert
IF foo > 10
FOR 5m
LABELS {foo="bar"}
ANNOTATIONS {notify="team-a"}`
if in.String() != expected {
t.Fatalf("expected:\n%s\ngot:\n%s\n", expected, in.String())
}
}
func TestExprString(t *testing.T) {
// A list of valid expressions that are expected to be
// returned as out when calling String(). If out is empty the output