@@ -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 ) {
@@ -29,6 +30,7 @@ func TestAlertingExecutor(t *testing.T) {
29
30
30
31
handler .Eval (context )
31
32
So (context .Firing , ShouldEqual , true )
33
+ So (context .ConditionEvals , ShouldEqual , "true = true" )
32
34
})
33
35
34
36
Convey ("Show return false with not passing asdf" , func () {
@@ -41,6 +43,89 @@ func TestAlertingExecutor(t *testing.T) {
41
43
42
44
handler .Eval (context )
43
45
So (context .Firing , ShouldEqual , false )
46
+ So (context .ConditionEvals , ShouldEqual , "[true AND false] = false" )
47
+ })
48
+
49
+ Convey ("Show return true if any of the condition is passing with OR operator" , func () {
50
+ context := NewEvalContext (context .TODO (), & Rule {
51
+ Conditions : []Condition {
52
+ & conditionStub {firing : true , operator : "and" },
53
+ & conditionStub {firing : false , operator : "or" },
54
+ },
55
+ })
56
+
57
+ handler .Eval (context )
58
+ So (context .Firing , ShouldEqual , true )
59
+ So (context .ConditionEvals , ShouldEqual , "[true OR false] = true" )
60
+ })
61
+
62
+ Convey ("Show return false if any of the condition is failing with AND operator" , func () {
63
+ context := NewEvalContext (context .TODO (), & Rule {
64
+ Conditions : []Condition {
65
+ & conditionStub {firing : true , operator : "and" },
66
+ & conditionStub {firing : false , operator : "and" },
67
+ },
68
+ })
69
+
70
+ handler .Eval (context )
71
+ So (context .Firing , ShouldEqual , false )
72
+ So (context .ConditionEvals , ShouldEqual , "[true AND false] = false" )
73
+ })
74
+
75
+ Convey ("Show return true if one condition is failing with nested OR operator" , func () {
76
+ context := NewEvalContext (context .TODO (), & Rule {
77
+ Conditions : []Condition {
78
+ & conditionStub {firing : true , operator : "and" },
79
+ & conditionStub {firing : true , operator : "and" },
80
+ & conditionStub {firing : false , operator : "or" },
81
+ },
82
+ })
83
+
84
+ handler .Eval (context )
85
+ So (context .Firing , ShouldEqual , true )
86
+ So (context .ConditionEvals , ShouldEqual , "[[true AND true] OR false] = true" )
87
+ })
88
+
89
+ Convey ("Show return false if one condition is passing with nested OR operator" , func () {
90
+ context := NewEvalContext (context .TODO (), & Rule {
91
+ Conditions : []Condition {
92
+ & conditionStub {firing : true , operator : "and" },
93
+ & conditionStub {firing : false , operator : "and" },
94
+ & conditionStub {firing : false , operator : "or" },
95
+ },
96
+ })
97
+
98
+ handler .Eval (context )
99
+ So (context .Firing , ShouldEqual , false )
100
+ So (context .ConditionEvals , ShouldEqual , "[[true AND false] OR false] = false" )
101
+ })
102
+
103
+ Convey ("Show return false if a condition is failing with nested AND operator" , func () {
104
+ context := NewEvalContext (context .TODO (), & Rule {
105
+ Conditions : []Condition {
106
+ & conditionStub {firing : true , operator : "and" },
107
+ & conditionStub {firing : false , operator : "and" },
108
+ & conditionStub {firing : true , operator : "and" },
109
+ },
110
+ })
111
+
112
+ handler .Eval (context )
113
+ So (context .Firing , ShouldEqual , false )
114
+ So (context .ConditionEvals , ShouldEqual , "[[true AND false] AND true] = false" )
115
+ })
116
+
117
+ Convey ("Show return true if a condition is passing with nested OR operator" , func () {
118
+ context := NewEvalContext (context .TODO (), & Rule {
119
+ Conditions : []Condition {
120
+ & conditionStub {firing : true , operator : "and" },
121
+ & conditionStub {firing : false , operator : "or" },
122
+ & conditionStub {firing : true , operator : "or" },
123
+ },
124
+ })
125
+
126
+ handler .Eval (context )
127
+ So (context .Firing , ShouldEqual , true )
128
+ So (context .ConditionEvals , ShouldEqual , "[[true OR false] OR true] = true" )
44
129
})
45
130
})
46
131
}
0 commit comments