@@ -8,12 +8,13 @@ import (
8
8
)
9
9
10
10
type conditionStub struct {
11
- firing bool
12
- matches []* EvalMatch
11
+ firing bool
12
+ operator string
13
+ matches []* EvalMatch
13
14
}
14
15
15
16
func (c * conditionStub ) Eval (context * EvalContext ) (* ConditionResult , error ) {
16
- return & ConditionResult {Firing : c .firing , EvalMatches : c .matches }, nil
17
+ return & ConditionResult {Firing : c .firing , EvalMatches : c .matches , Operator : c . operator }, nil
17
18
}
18
19
19
20
func TestAlertingExecutor (t * testing.T ) {
@@ -42,5 +43,81 @@ func TestAlertingExecutor(t *testing.T) {
42
43
handler .Eval (context )
43
44
So (context .Firing , ShouldEqual , false )
44
45
})
46
+
47
+ Convey ("Show return true if any of the condition is passing with OR operator" , func () {
48
+ context := NewEvalContext (context .TODO (), & Rule {
49
+ Conditions : []Condition {
50
+ & conditionStub {firing : true , operator : "and" },
51
+ & conditionStub {firing : false , operator : "or" },
52
+ },
53
+ })
54
+
55
+ handler .Eval (context )
56
+ So (context .Firing , ShouldEqual , true )
57
+ })
58
+
59
+ Convey ("Show return false if any of the condition is failing with AND operator" , func () {
60
+ context := NewEvalContext (context .TODO (), & Rule {
61
+ Conditions : []Condition {
62
+ & conditionStub {firing : true , operator : "and" },
63
+ & conditionStub {firing : false , operator : "and" },
64
+ },
65
+ })
66
+
67
+ handler .Eval (context )
68
+ So (context .Firing , ShouldEqual , false )
69
+ })
70
+
71
+ Convey ("Show return true if one condition is failing with nested OR operator" , func () {
72
+ context := NewEvalContext (context .TODO (), & Rule {
73
+ Conditions : []Condition {
74
+ & conditionStub {firing : true , operator : "and" },
75
+ & conditionStub {firing : true , operator : "and" },
76
+ & conditionStub {firing : false , operator : "or" },
77
+ },
78
+ })
79
+
80
+ handler .Eval (context )
81
+ So (context .Firing , ShouldEqual , true )
82
+ })
83
+
84
+ Convey ("Show return false if one condition is passing with nested OR operator" , func () {
85
+ context := NewEvalContext (context .TODO (), & Rule {
86
+ Conditions : []Condition {
87
+ & conditionStub {firing : true , operator : "and" },
88
+ & conditionStub {firing : false , operator : "and" },
89
+ & conditionStub {firing : false , operator : "or" },
90
+ },
91
+ })
92
+
93
+ handler .Eval (context )
94
+ So (context .Firing , ShouldEqual , false )
95
+ })
96
+
97
+ Convey ("Show return false if a condition is failing with nested AND operator" , func () {
98
+ context := NewEvalContext (context .TODO (), & Rule {
99
+ Conditions : []Condition {
100
+ & conditionStub {firing : true , operator : "and" },
101
+ & conditionStub {firing : false , operator : "and" },
102
+ & conditionStub {firing : true , operator : "and" },
103
+ },
104
+ })
105
+
106
+ handler .Eval (context )
107
+ So (context .Firing , ShouldEqual , false )
108
+ })
109
+
110
+ Convey ("Show return true if a condition is passing with nested OR operator" , func () {
111
+ context := NewEvalContext (context .TODO (), & Rule {
112
+ Conditions : []Condition {
113
+ & conditionStub {firing : true , operator : "and" },
114
+ & conditionStub {firing : false , operator : "or" },
115
+ & conditionStub {firing : true , operator : "or" },
116
+ },
117
+ })
118
+
119
+ handler .Eval (context )
120
+ So (context .Firing , ShouldEqual , true )
121
+ })
45
122
})
46
123
}
0 commit comments