mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(alerting): progress on alerting backend
This commit is contained in:
@@ -3,7 +3,10 @@ package alerting
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/tsdb"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@@ -11,6 +14,11 @@ func TestQueryCondition(t *testing.T) {
|
||||
|
||||
Convey("when evaluating query condition", t, func() {
|
||||
|
||||
bus.AddHandler("test", func(query *m.GetDataSourceByIdQuery) error {
|
||||
query.Result = &m.DataSource{Id: 1, Type: "graphite"}
|
||||
return nil
|
||||
})
|
||||
|
||||
Convey("Given avg() and > 100", func() {
|
||||
|
||||
jsonModel, err := simplejson.NewJson([]byte(`{
|
||||
@@ -29,9 +37,25 @@ func TestQueryCondition(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
Convey("Should set result to triggered when avg is above 100", func() {
|
||||
context := &AlertResultContext{}
|
||||
context := &AlertResultContext{
|
||||
Rule: &AlertRule{},
|
||||
}
|
||||
|
||||
condition.HandleRequest = func(req *tsdb.Request) (*tsdb.Response, error) {
|
||||
return &tsdb.Response{
|
||||
Results: map[string]*tsdb.QueryResult{
|
||||
"A": &tsdb.QueryResult{
|
||||
Series: tsdb.TimeSeriesSlice{
|
||||
tsdb.NewTimeSeries("test1", [][2]float64{{120, 0}}),
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
condition.Eval(context)
|
||||
|
||||
So(context.Error, ShouldBeNil)
|
||||
So(context.Triggered, ShouldBeTrue)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user