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
def4632f
Commit
def4632f
authored
Aug 18, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test(alerting): add falsification test
parent
cbe7f8b6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
15 deletions
+28
-15
pkg/services/alerting/conditions/evaluator_test.go
+28
-15
No files found.
pkg/services/alerting/conditions/evaluator_test.go
View file @
def4632f
...
...
@@ -8,42 +8,55 @@ import (
.
"github.com/smartystreets/goconvey/convey"
)
func
test
(
json
string
,
reducedValue
float64
)
bool
{
func
evalutorScenario
(
json
string
,
reducedValue
float64
,
datapoints
...
float64
)
bool
{
jsonModel
,
err
:=
simplejson
.
NewJson
([]
byte
(
json
))
So
(
err
,
ShouldBeNil
)
evaluator
,
err
:=
NewAlertEvaluator
(
jsonModel
)
So
(
err
,
ShouldBeNil
)
return
evaluator
.
Eval
(
&
tsdb
.
TimeSeries
{},
reducedValue
)
var
timeserie
[][
2
]
float64
dummieTimestamp
:=
float64
(
521452145
)
for
_
,
v
:=
range
datapoints
{
timeserie
=
append
(
timeserie
,
[
2
]
float64
{
v
,
dummieTimestamp
})
}
tsdb
:=
&
tsdb
.
TimeSeries
{
Name
:
"test time serie"
,
Points
:
timeserie
,
}
return
evaluator
.
Eval
(
tsdb
,
reducedValue
)
}
func
TestEvalutors
(
t
*
testing
.
T
)
{
Convey
(
"greater then"
,
t
,
func
()
{
So
(
test
(
`{"type": "gt", "params": [1] }`
,
3
),
ShouldBeTrue
)
So
(
test
(
`{"type": "gt", "params": [3] }`
,
1
),
ShouldBeFalse
)
So
(
evalutorScenario
(
`{"type": "gt", "params": [1] }`
,
3
),
ShouldBeTrue
)
So
(
evalutorScenario
(
`{"type": "gt", "params": [3] }`
,
1
),
ShouldBeFalse
)
})
Convey
(
"less then"
,
t
,
func
()
{
So
(
test
(
`{"type": "lt", "params": [1] }`
,
3
),
ShouldBeFalse
)
So
(
test
(
`{"type": "lt", "params": [3] }`
,
1
),
ShouldBeTrue
)
So
(
evalutorScenario
(
`{"type": "lt", "params": [1] }`
,
3
),
ShouldBeFalse
)
So
(
evalutorScenario
(
`{"type": "lt", "params": [3] }`
,
1
),
ShouldBeTrue
)
})
Convey
(
"within_range"
,
t
,
func
()
{
So
(
test
(
`{"type": "within_range", "params": [1, 100] }`
,
3
),
ShouldBeTrue
)
So
(
test
(
`{"type": "within_range", "params": [1, 100] }`
,
300
),
ShouldBeFalse
)
So
(
test
(
`{"type": "within_range", "params": [100, 1] }`
,
3
),
ShouldBeTrue
)
So
(
test
(
`{"type": "within_range", "params": [100, 1] }`
,
300
),
ShouldBeFalse
)
So
(
evalutorScenario
(
`{"type": "within_range", "params": [1, 100] }`
,
3
),
ShouldBeTrue
)
So
(
evalutorScenario
(
`{"type": "within_range", "params": [1, 100] }`
,
300
),
ShouldBeFalse
)
So
(
evalutorScenario
(
`{"type": "within_range", "params": [100, 1] }`
,
3
),
ShouldBeTrue
)
So
(
evalutorScenario
(
`{"type": "within_range", "params": [100, 1] }`
,
300
),
ShouldBeFalse
)
})
Convey
(
"outside_range"
,
t
,
func
()
{
So
(
test
(
`{"type": "outside_range", "params": [1, 100] }`
,
1000
),
ShouldBeTrue
)
So
(
test
(
`{"type": "outside_range", "params": [1, 100] }`
,
50
),
ShouldBeFalse
)
So
(
test
(
`{"type": "outside_range", "params": [100, 1] }`
,
1000
),
ShouldBeTrue
)
So
(
test
(
`{"type": "outside_range", "params": [100, 1] }`
,
50
),
ShouldBeFalse
)
So
(
evalutorScenario
(
`{"type": "outside_range", "params": [1, 100] }`
,
1000
),
ShouldBeTrue
)
So
(
evalutorScenario
(
`{"type": "outside_range", "params": [1, 100] }`
,
50
),
ShouldBeFalse
)
So
(
evalutorScenario
(
`{"type": "outside_range", "params": [100, 1] }`
,
1000
),
ShouldBeTrue
)
So
(
evalutorScenario
(
`{"type": "outside_range", "params": [100, 1] }`
,
50
),
ShouldBeFalse
)
})
Convey
(
"no_value"
,
t
,
func
()
{
So
(
test
(
`{"type": "no_value", "params": [] }`
,
1000
),
ShouldBeTrue
)
So
(
evalutorScenario
(
`{"type": "no_value", "params": [] }`
,
1000
),
ShouldBeTrue
)
So
(
evalutorScenario
(
`{"type": "no_value", "params": [] }`
,
1000
,
1
,
2
),
ShouldBeFalse
)
})
}
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