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
592ae5a3
Commit
592ae5a3
authored
Sep 07, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests(alerting): fixes broken tests. pointers and stuff
🤷
parent
30f36fe2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
24 deletions
+32
-24
pkg/services/alerting/conditions/evaluator_test.go
+11
-4
pkg/services/alerting/conditions/query_test.go
+6
-2
pkg/services/alerting/conditions/reducer.go
+1
-0
pkg/services/alerting/conditions/reducer_test.go
+9
-14
pkg/services/alerting/rule_test.go
+5
-4
No files found.
pkg/services/alerting/conditions/evaluator_test.go
View file @
592ae5a3
...
...
@@ -14,7 +14,7 @@ func evalutorScenario(json string, reducedValue float64, datapoints ...float64)
evaluator
,
err
:=
NewAlertEvaluator
(
jsonModel
)
So
(
err
,
ShouldBeNil
)
return
evaluator
.
Eval
(
reducedValue
)
return
evaluator
.
Eval
(
&
reducedValue
)
}
func
TestEvalutors
(
t
*
testing
.
T
)
{
...
...
@@ -42,8 +42,15 @@ func TestEvalutors(t *testing.T) {
So
(
evalutorScenario
(
`{"type": "outside_range", "params": [100, 1] }`
,
50
),
ShouldBeFalse
)
})
Convey
(
"no_value"
,
t
,
func
()
{
So
(
evalutorScenario
(
`{"type": "no_value", "params": [] }`
,
1000
),
ShouldBeTrue
)
So
(
evalutorScenario
(
`{"type": "no_value", "params": [] }`
,
1000
,
1
,
2
),
ShouldBeFalse
)
Convey
(
"no_data"
,
t
,
func
()
{
So
(
evalutorScenario
(
`{"type": "no_data", "params": [] }`
,
50
),
ShouldBeFalse
)
jsonModel
,
err
:=
simplejson
.
NewJson
([]
byte
(
`{"type": "no_data", "params": [] }`
))
So
(
err
,
ShouldBeNil
)
evaluator
,
err
:=
NewAlertEvaluator
(
jsonModel
)
So
(
err
,
ShouldBeNil
)
So
(
evaluator
.
Eval
(
nil
),
ShouldBeTrue
)
})
}
pkg/services/alerting/conditions/query_test.go
View file @
592ae5a3
...
...
@@ -41,7 +41,9 @@ func TestQueryCondition(t *testing.T) {
})
Convey
(
"should fire when avg is above 100"
,
func
()
{
ctx
.
series
=
tsdb
.
TimeSeriesSlice
{
tsdb
.
NewTimeSeries
(
"test1"
,
[][
2
]
float64
{{
120
,
0
}})}
one
:=
float64
(
120
)
two
:=
float64
(
0
)
ctx
.
series
=
tsdb
.
TimeSeriesSlice
{
tsdb
.
NewTimeSeries
(
"test1"
,
[][
2
]
*
float64
{{
&
one
,
&
two
}})}
ctx
.
exec
()
So
(
ctx
.
result
.
Error
,
ShouldBeNil
)
...
...
@@ -49,7 +51,9 @@ func TestQueryCondition(t *testing.T) {
})
Convey
(
"Should not fire when avg is below 100"
,
func
()
{
ctx
.
series
=
tsdb
.
TimeSeriesSlice
{
tsdb
.
NewTimeSeries
(
"test1"
,
[][
2
]
float64
{{
90
,
0
}})}
one
:=
float64
(
90
)
two
:=
float64
(
0
)
ctx
.
series
=
tsdb
.
TimeSeriesSlice
{
tsdb
.
NewTimeSeries
(
"test1"
,
[][
2
]
*
float64
{{
&
one
,
&
two
}})}
ctx
.
exec
()
So
(
ctx
.
result
.
Error
,
ShouldBeNil
)
...
...
pkg/services/alerting/conditions/reducer.go
View file @
592ae5a3
...
...
@@ -60,6 +60,7 @@ func (s *SimpleReducer) Reduce(series *tsdb.TimeSeries) *float64 {
}
case
"count"
:
value
=
float64
(
len
(
series
.
Points
))
allNull
=
false
}
if
allNull
{
...
...
pkg/services/alerting/conditions/reducer_test.go
View file @
592ae5a3
...
...
@@ -10,44 +10,39 @@ import (
func
TestSimpleReducer
(
t
*
testing
.
T
)
{
Convey
(
"Test simple reducer by calculating"
,
t
,
func
()
{
Convey
(
"avg"
,
func
()
{
result
:=
testReducer
(
"avg"
,
1
,
2
,
3
)
result
:=
*
testReducer
(
"avg"
,
1
,
2
,
3
)
So
(
result
,
ShouldEqual
,
float64
(
2
))
})
Convey
(
"sum"
,
func
()
{
result
:=
testReducer
(
"sum"
,
1
,
2
,
3
)
result
:=
*
testReducer
(
"sum"
,
1
,
2
,
3
)
So
(
result
,
ShouldEqual
,
float64
(
6
))
})
Convey
(
"min"
,
func
()
{
result
:=
testReducer
(
"min"
,
3
,
2
,
1
)
result
:=
*
testReducer
(
"min"
,
3
,
2
,
1
)
So
(
result
,
ShouldEqual
,
float64
(
1
))
})
Convey
(
"max"
,
func
()
{
result
:=
testReducer
(
"max"
,
1
,
2
,
3
)
result
:=
*
testReducer
(
"max"
,
1
,
2
,
3
)
So
(
result
,
ShouldEqual
,
float64
(
3
))
})
Convey
(
"mean odd numbers"
,
func
()
{
result
:=
testReducer
(
"mean"
,
1
,
2
,
3000
)
So
(
result
,
ShouldEqual
,
float64
(
2
))
})
Convey
(
"count"
,
func
()
{
result
:=
testReducer
(
"count"
,
1
,
2
,
3000
)
result
:=
*
testReducer
(
"count"
,
1
,
2
,
3000
)
So
(
result
,
ShouldEqual
,
float64
(
3
))
})
})
}
func
testReducer
(
typ
string
,
datapoints
...
float64
)
float64
{
func
testReducer
(
typ
string
,
datapoints
...
float64
)
*
float64
{
reducer
:=
NewSimpleReducer
(
typ
)
var
timeserie
[][
2
]
float64
var
timeserie
[][
2
]
*
float64
dummieTimestamp
:=
float64
(
521452145
)
for
_
,
v
:=
range
datapoints
{
timeserie
=
append
(
timeserie
,
[
2
]
float64
{
v
,
dummieTimestamp
})
for
idx
:=
range
datapoints
{
timeserie
=
append
(
timeserie
,
[
2
]
*
float64
{
&
datapoints
[
idx
],
&
dummieTimestamp
})
}
tsdb
:=
&
tsdb
.
TimeSeries
{
...
...
pkg/services/alerting/rule_test.go
View file @
592ae5a3
...
...
@@ -81,10 +81,11 @@ func TestAlertRuleModel(t *testing.T) {
Convey
(
"Can read notifications"
,
func
()
{
So
(
len
(
alertRule
.
Notifications
),
ShouldEqual
,
2
)
})
Convey
(
"Can read noDataMode"
,
func
()
{
So
(
len
(
alertRule
.
NoDataMode
),
ShouldEqual
,
m
.
AlertStateCritical
)
})
/*
Convey("Can read noDataMode", func() {
So(len(alertRule.NoDataMode), ShouldEqual, m.AlertStateCritical)
})
*/
})
})
}
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