mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
Alerting: Add tests for matching captures (#71928)
This commit adds tests for matching captures, which we do not have at present.
This commit is contained in:
parent
58729a331f
commit
f1af0502db
@ -596,6 +596,111 @@ func TestEvaluate(t *testing.T) {
|
||||
"ref_id": "A",
|
||||
},
|
||||
}},
|
||||
}, {
|
||||
name: "results contains captured values for exact label matches",
|
||||
cond: models.Condition{
|
||||
Condition: "B",
|
||||
},
|
||||
resp: backend.QueryDataResponse{
|
||||
Responses: backend.Responses{
|
||||
"A": {
|
||||
Frames: []*data.Frame{{
|
||||
RefID: "A",
|
||||
Fields: []*data.Field{
|
||||
data.NewField(
|
||||
"Value",
|
||||
data.Labels{"foo": "bar"},
|
||||
[]*float64{util.Pointer(10.0)},
|
||||
),
|
||||
},
|
||||
}},
|
||||
},
|
||||
"B": {
|
||||
Frames: []*data.Frame{{
|
||||
RefID: "B",
|
||||
Fields: []*data.Field{
|
||||
data.NewField(
|
||||
"Value",
|
||||
data.Labels{"foo": "bar"},
|
||||
[]*float64{util.Pointer(1.0)},
|
||||
),
|
||||
},
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: Results{{
|
||||
State: Alerting,
|
||||
Instance: data.Labels{
|
||||
"foo": "bar",
|
||||
},
|
||||
Values: map[string]NumberValueCapture{
|
||||
"A": {
|
||||
Var: "A",
|
||||
Labels: data.Labels{"foo": "bar"},
|
||||
Value: util.Pointer(10.0),
|
||||
},
|
||||
"B": {
|
||||
Var: "B",
|
||||
Labels: data.Labels{"foo": "bar"},
|
||||
Value: util.Pointer(1.0),
|
||||
},
|
||||
},
|
||||
EvaluationString: "[ var='A' labels={foo=bar} value=10 ], [ var='B' labels={foo=bar} value=1 ]",
|
||||
}},
|
||||
}, {
|
||||
name: "results contains captured values for subset of labels",
|
||||
cond: models.Condition{
|
||||
Condition: "B",
|
||||
},
|
||||
resp: backend.QueryDataResponse{
|
||||
Responses: backend.Responses{
|
||||
"A": {
|
||||
Frames: []*data.Frame{{
|
||||
RefID: "A",
|
||||
Fields: []*data.Field{
|
||||
data.NewField(
|
||||
"Value",
|
||||
data.Labels{"foo": "bar"},
|
||||
[]*float64{util.Pointer(10.0)},
|
||||
),
|
||||
},
|
||||
}},
|
||||
},
|
||||
"B": {
|
||||
Frames: []*data.Frame{{
|
||||
RefID: "B",
|
||||
Fields: []*data.Field{
|
||||
data.NewField(
|
||||
"Value",
|
||||
data.Labels{"foo": "bar", "bar": "baz"},
|
||||
[]*float64{util.Pointer(1.0)},
|
||||
),
|
||||
},
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: Results{{
|
||||
State: Alerting,
|
||||
Instance: data.Labels{
|
||||
"foo": "bar",
|
||||
"bar": "baz",
|
||||
},
|
||||
Values: map[string]NumberValueCapture{
|
||||
"A": {
|
||||
Var: "A",
|
||||
Labels: data.Labels{"foo": "bar"},
|
||||
Value: util.Pointer(10.0),
|
||||
},
|
||||
"B": {
|
||||
Var: "B",
|
||||
Labels: data.Labels{"foo": "bar", "bar": "baz"},
|
||||
Value: util.Pointer(1.0),
|
||||
},
|
||||
},
|
||||
EvaluationString: "[ var='A' labels={foo=bar} value=10 ], [ var='B' labels={bar=baz, foo=bar} value=1 ]",
|
||||
}},
|
||||
}}
|
||||
|
||||
for _, tc := range cases {
|
||||
|
Loading…
Reference in New Issue
Block a user