Skip to content

Commit aae33b3

Browse files
committed
Added tests for firingEvaluation string
1 parent fc82dac commit aae33b3

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pkg/services/alerting/eval_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (e *DefaultEvalHandler) Eval(context *EvalContext) {
4747
if i > 0 {
4848
firingEval = "[" + firingEval + " " + operator + " " + strconv.FormatBool(cr.Firing) + "]"
4949
} else {
50-
firingEval = "[" + strconv.FormatBool(firing) + "]"
50+
firingEval = strconv.FormatBool(firing)
5151
}
5252

5353
context.EvalMatches = append(context.EvalMatches, cr.EvalMatches...)

pkg/services/alerting/eval_handler_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func TestAlertingExecutor(t *testing.T) {
3030

3131
handler.Eval(context)
3232
So(context.Firing, ShouldEqual, true)
33+
So(context.FiringEval, ShouldEqual, "true = true")
3334
})
3435

3536
Convey("Show return false with not passing asdf", func() {
@@ -42,6 +43,7 @@ func TestAlertingExecutor(t *testing.T) {
4243

4344
handler.Eval(context)
4445
So(context.Firing, ShouldEqual, false)
46+
So(context.FiringEval, ShouldEqual, "[true AND false] = false")
4547
})
4648

4749
Convey("Show return true if any of the condition is passing with OR operator", func() {
@@ -54,6 +56,7 @@ func TestAlertingExecutor(t *testing.T) {
5456

5557
handler.Eval(context)
5658
So(context.Firing, ShouldEqual, true)
59+
So(context.FiringEval, ShouldEqual, "[true OR false] = true")
5760
})
5861

5962
Convey("Show return false if any of the condition is failing with AND operator", func() {
@@ -66,6 +69,7 @@ func TestAlertingExecutor(t *testing.T) {
6669

6770
handler.Eval(context)
6871
So(context.Firing, ShouldEqual, false)
72+
So(context.FiringEval, ShouldEqual, "[true AND false] = false")
6973
})
7074

7175
Convey("Show return true if one condition is failing with nested OR operator", func() {
@@ -79,6 +83,7 @@ func TestAlertingExecutor(t *testing.T) {
7983

8084
handler.Eval(context)
8185
So(context.Firing, ShouldEqual, true)
86+
So(context.FiringEval, ShouldEqual, "[[true AND true] OR false] = true")
8287
})
8388

8489
Convey("Show return false if one condition is passing with nested OR operator", func() {
@@ -92,6 +97,7 @@ func TestAlertingExecutor(t *testing.T) {
9297

9398
handler.Eval(context)
9499
So(context.Firing, ShouldEqual, false)
100+
So(context.FiringEval, ShouldEqual, "[[true AND false] OR false] = false")
95101
})
96102

97103
Convey("Show return false if a condition is failing with nested AND operator", func() {
@@ -105,6 +111,7 @@ func TestAlertingExecutor(t *testing.T) {
105111

106112
handler.Eval(context)
107113
So(context.Firing, ShouldEqual, false)
114+
So(context.FiringEval, ShouldEqual, "[[true AND false] AND true] = false")
108115
})
109116

110117
Convey("Show return true if a condition is passing with nested OR operator", func() {
@@ -118,6 +125,7 @@ func TestAlertingExecutor(t *testing.T) {
118125

119126
handler.Eval(context)
120127
So(context.Firing, ShouldEqual, true)
128+
So(context.FiringEval, ShouldEqual, "[[true OR false] OR true] = true")
121129
})
122130
})
123131
}

0 commit comments

Comments
 (0)