Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
8d0bcd23
Commit
8d0bcd23
authored
Nov 15, 2016
by
utkarshcmu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for checking nested operators
parent
dfb1b191
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
1 deletions
+78
-1
pkg/services/alerting/eval_handler_test.go
+78
-1
No files found.
pkg/services/alerting/eval_handler_test.go
View file @
8d0bcd23
...
@@ -9,11 +9,12 @@ import (
...
@@ -9,11 +9,12 @@ import (
type
conditionStub
struct
{
type
conditionStub
struct
{
firing
bool
firing
bool
operator
string
matches
[]
*
EvalMatch
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) {
...
@@ -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
)
})
})
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment