Commit 2cf72715 by bergquist

test(alerting): fixes broken unit tests

parent d52fc8d0
......@@ -23,7 +23,7 @@ type AlertRule struct {
Query AlertQuery
Transform string
TransformParams simplejson.Json
Transformer transformer.Transformer
Transformer transformers.Transformer
}
func getTimeDurationStringToSeconds(str string) int64 {
......@@ -56,7 +56,7 @@ func NewAlertRuleFromDBModel(ruleDef *m.Alert) (*AlertRule, error) {
if model.Transform == "aggregation" {
method := ruleDef.Expression.Get("transform").Get("method").MustString()
model.Transformer = transformer.NewAggregationTransformer(method)
model.Transformer = transformers.NewAggregationTransformer(method)
}
query := ruleDef.Expression.Get("query")
......
......@@ -4,6 +4,7 @@ import (
"testing"
"github.com/grafana/grafana/pkg/services/alerting/alertstates"
"github.com/grafana/grafana/pkg/services/alerting/transformers"
"github.com/grafana/grafana/pkg/tsdb"
. "github.com/smartystreets/goconvey/convey"
)
......@@ -16,7 +17,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey("Show return ok since avg is above 2", func() {
rule := &AlertRule{
Critical: Level{Level: 10, Operator: ">"},
Transformer: &AggregationTransformer{Method: "avg"},
Transformer: transformers.NewAggregationTransformer("avg"),
}
timeSeries := []*tsdb.TimeSeries{
......@@ -30,7 +31,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey("Show return critical since below 2", func() {
rule := &AlertRule{
Critical: Level{Level: 10, Operator: "<"},
Transformer: &AggregationTransformer{Method: "avg"},
Transformer: transformers.NewAggregationTransformer("avg"),
}
timeSeries := []*tsdb.TimeSeries{
......@@ -44,7 +45,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey("Show return critical since sum is above 10", func() {
rule := &AlertRule{
Critical: Level{Level: 10, Operator: ">"},
Transformer: &AggregationTransformer{Method: "sum"},
Transformer: transformers.NewAggregationTransformer("sum"),
}
timeSeries := []*tsdb.TimeSeries{
......@@ -58,7 +59,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey("Show return ok since avg is below 10", func() {
rule := &AlertRule{
Critical: Level{Level: 10, Operator: ">"},
Transformer: &AggregationTransformer{Method: "avg"},
Transformer: transformers.NewAggregationTransformer("avg"),
}
timeSeries := []*tsdb.TimeSeries{
......@@ -72,7 +73,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey("Show return ok since min is below 10", func() {
rule := &AlertRule{
Critical: Level{Level: 10, Operator: ">"},
Transformer: &AggregationTransformer{Method: "avg"},
Transformer: transformers.NewAggregationTransformer("avg"),
}
timeSeries := []*tsdb.TimeSeries{
......@@ -86,7 +87,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey("Show return ok since max is above 10", func() {
rule := &AlertRule{
Critical: Level{Level: 10, Operator: ">"},
Transformer: &AggregationTransformer{Method: "max"},
Transformer: transformers.NewAggregationTransformer("max"),
}
timeSeries := []*tsdb.TimeSeries{
......@@ -103,7 +104,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey("both are ok", func() {
rule := &AlertRule{
Critical: Level{Level: 10, Operator: ">"},
Transformer: &AggregationTransformer{Method: "avg"},
Transformer: transformers.NewAggregationTransformer("avg"),
}
timeSeries := []*tsdb.TimeSeries{
......@@ -118,7 +119,7 @@ func TestAlertingExecutor(t *testing.T) {
Convey("first serie is good, second is critical", func() {
rule := &AlertRule{
Critical: Level{Level: 10, Operator: ">"},
Transformer: &AggregationTransformer{Method: "avg"},
Transformer: transformers.NewAggregationTransformer("avg"),
}
timeSeries := []*tsdb.TimeSeries{
......
package transformer
package transformers
import (
"fmt"
......
package transformer
package transformers
import "github.com/grafana/grafana/pkg/tsdb"
......
......@@ -18,24 +18,24 @@ func GetAlertRuleChanges(query *m.GetAlertChangesQuery) error {
params := make([]interface{}, 0)
sql.WriteString(`SELECT
alert_rule_change.id,
alert_rule_change.org_id,
alert_rule_change.alert_id,
alert_rule_change.type,
alert_rule_change.created
FROM alert_rule_change
alert_change.id,
alert_change.org_id,
alert_change.alert_id,
alert_change.type,
alert_change.created
FROM alert_change
`)
sql.WriteString(`WHERE alert_rule_change.org_id = ?`)
sql.WriteString(`WHERE alert_change.org_id = ?`)
params = append(params, query.OrgId)
if query.SinceId != 0 {
sql.WriteString(`AND alert_rule_change.id >= ?`)
sql.WriteString(`AND alert_change.id >= ?`)
params = append(params, query.SinceId)
}
if query.Limit != 0 {
sql.WriteString(` ORDER BY alert_rule_change.id DESC LIMIT ?`)
sql.WriteString(` ORDER BY alert_change.id DESC LIMIT ?`)
params = append(params, query.Limit)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment