feat(alerting): progress on alerting backend

This commit is contained in:
Torkel Ödegaard
2016-07-20 14:28:02 +02:00
parent 3219d98a92
commit 0ce55600bb
6 changed files with 138 additions and 17 deletions

View File

@@ -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)
})
})