mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Added tests for checking nested operators
This commit is contained in:
parent
dfb1b1918c
commit
8d0bcd23f8
@ -8,12 +8,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type conditionStub struct {
|
type conditionStub struct {
|
||||||
firing bool
|
firing bool
|
||||||
matches []*EvalMatch
|
operator string
|
||||||
|
matches []*EvalMatch
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *conditionStub) Eval(context *EvalContext) (*ConditionResult, error) {
|
func (c *conditionStub) Eval(context *EvalContext) (*ConditionResult, error) {
|
||||||
return &ConditionResult{Firing: c.firing, EvalMatches: c.matches}, nil
|
return &ConditionResult{Firing: c.firing, EvalMatches: c.matches, Operator: c.operator}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAlertingExecutor(t *testing.T) {
|
func TestAlertingExecutor(t *testing.T) {
|
||||||
@ -42,5 +43,81 @@ func TestAlertingExecutor(t *testing.T) {
|
|||||||
handler.Eval(context)
|
handler.Eval(context)
|
||||||
So(context.Firing, ShouldEqual, false)
|
So(context.Firing, ShouldEqual, false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Convey("Show return true if any of the condition is passing with OR operator", func() {
|
||||||
|
context := NewEvalContext(context.TODO(), &Rule{
|
||||||
|
Conditions: []Condition{
|
||||||
|
&conditionStub{firing: true, operator: "and"},
|
||||||
|
&conditionStub{firing: false, operator: "or"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
handler.Eval(context)
|
||||||
|
So(context.Firing, ShouldEqual, true)
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("Show return false if any of the condition is failing with AND operator", func() {
|
||||||
|
context := NewEvalContext(context.TODO(), &Rule{
|
||||||
|
Conditions: []Condition{
|
||||||
|
&conditionStub{firing: true, operator: "and"},
|
||||||
|
&conditionStub{firing: false, operator: "and"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
handler.Eval(context)
|
||||||
|
So(context.Firing, ShouldEqual, false)
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("Show return true if one condition is failing with nested OR operator", func() {
|
||||||
|
context := NewEvalContext(context.TODO(), &Rule{
|
||||||
|
Conditions: []Condition{
|
||||||
|
&conditionStub{firing: true, operator: "and"},
|
||||||
|
&conditionStub{firing: true, operator: "and"},
|
||||||
|
&conditionStub{firing: false, operator: "or"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
handler.Eval(context)
|
||||||
|
So(context.Firing, ShouldEqual, true)
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("Show return false if one condition is passing with nested OR operator", func() {
|
||||||
|
context := NewEvalContext(context.TODO(), &Rule{
|
||||||
|
Conditions: []Condition{
|
||||||
|
&conditionStub{firing: true, operator: "and"},
|
||||||
|
&conditionStub{firing: false, operator: "and"},
|
||||||
|
&conditionStub{firing: false, operator: "or"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
handler.Eval(context)
|
||||||
|
So(context.Firing, ShouldEqual, false)
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("Show return false if a condition is failing with nested AND operator", func() {
|
||||||
|
context := NewEvalContext(context.TODO(), &Rule{
|
||||||
|
Conditions: []Condition{
|
||||||
|
&conditionStub{firing: true, operator: "and"},
|
||||||
|
&conditionStub{firing: false, operator: "and"},
|
||||||
|
&conditionStub{firing: true, operator: "and"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
handler.Eval(context)
|
||||||
|
So(context.Firing, ShouldEqual, false)
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("Show return true if a condition is passing with nested OR operator", func() {
|
||||||
|
context := NewEvalContext(context.TODO(), &Rule{
|
||||||
|
Conditions: []Condition{
|
||||||
|
&conditionStub{firing: true, operator: "and"},
|
||||||
|
&conditionStub{firing: false, operator: "or"},
|
||||||
|
&conditionStub{firing: true, operator: "or"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
handler.Eval(context)
|
||||||
|
So(context.Firing, ShouldEqual, true)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user