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
238139fa
Commit
238139fa
authored
May 25, 2018
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
alerting: refactor tests
parent
21ade3f6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
76 deletions
+78
-76
pkg/services/alerting/eval_context_test.go
+78
-76
No files found.
pkg/services/alerting/eval_context_test.go
View file @
238139fa
...
...
@@ -9,91 +9,93 @@ import (
.
"github.com/smartystreets/goconvey/convey"
)
func
TestStateIsUpdatedWhenNeeded
(
t
*
testing
.
T
)
{
ctx
:=
NewEvalContext
(
context
.
TODO
(),
&
Rule
{
Conditions
:
[]
Condition
{
&
conditionStub
{
firing
:
true
}}})
t
.
Run
(
"ok -> alerting"
,
func
(
t
*
testing
.
T
)
{
ctx
.
PrevAlertState
=
models
.
AlertStateOK
ctx
.
Rule
.
State
=
models
.
AlertStateAlerting
if
!
ctx
.
ShouldUpdateAlertState
()
{
t
.
Fatalf
(
"expected should updated to be true"
)
}
})
t
.
Run
(
"ok -> ok"
,
func
(
t
*
testing
.
T
)
{
ctx
.
PrevAlertState
=
models
.
AlertStateOK
ctx
.
Rule
.
State
=
models
.
AlertStateOK
if
ctx
.
ShouldUpdateAlertState
()
{
t
.
Fatalf
(
"expected should updated to be false"
)
}
})
}
func
TestAlertingEvalContext
(
t
*
testing
.
T
)
{
Convey
(
"
Eval context
"
,
t
,
func
()
{
Convey
(
"
Should compute and replace properly new rule state
"
,
t
,
func
()
{
ctx
:=
NewEvalContext
(
context
.
TODO
(),
&
Rule
{
Conditions
:
[]
Condition
{
&
conditionStub
{
firing
:
true
}}})
dummieError
:=
fmt
.
Errorf
(
"dummie error"
)
Convey
(
"Should update alert state when needed"
,
func
()
{
Convey
(
"ok -> alerting"
,
func
()
{
ctx
.
PrevAlertState
=
models
.
AlertStateOK
ctx
.
Firing
=
true
Convey
(
"ok -> alerting"
,
func
()
{
ctx
.
PrevAlertState
=
models
.
AlertStateOK
ctx
.
Rule
.
State
=
models
.
AlertStateAlerting
ctx
.
Rule
.
State
=
ctx
.
GetNewState
()
So
(
ctx
.
Rule
.
State
,
ShouldEqual
,
models
.
AlertStateAlerting
)
})
So
(
ctx
.
ShouldUpdateAlertState
(),
ShouldBeTrue
)
})
Convey
(
"ok -> error(alerting)"
,
func
()
{
ctx
.
PrevAlertState
=
models
.
AlertStateOK
ctx
.
Error
=
dummieError
ctx
.
Rule
.
ExecutionErrorState
=
models
.
ExecutionErrorSetAlerting
ctx
.
Rule
.
State
=
ctx
.
GetNewState
()
So
(
ctx
.
Rule
.
State
,
ShouldEqual
,
models
.
AlertStateAlerting
)
})
Convey
(
"ok -> ok"
,
func
()
{
ctx
.
PrevAlertState
=
models
.
AlertStateOK
ctx
.
Rule
.
State
=
models
.
AlertStateOK
Convey
(
"ok -> error(keep_last)"
,
func
()
{
ctx
.
PrevAlertState
=
models
.
AlertStateOK
ctx
.
Error
=
dummieError
ctx
.
Rule
.
ExecutionErrorState
=
models
.
ExecutionErrorKeepState
So
(
ctx
.
ShouldUpdateAlertState
(),
ShouldBeFalse
)
}
)
ctx
.
Rule
.
State
=
ctx
.
GetNewState
(
)
So
(
ctx
.
Rule
.
State
,
ShouldEqual
,
models
.
AlertStateOK
)
})
Convey
(
"Should compute and replace properly new rule state"
,
func
()
{
dummieError
:=
fmt
.
Errorf
(
"dummie error"
)
Convey
(
"ok -> alerting"
,
func
()
{
ctx
.
PrevAlertState
=
models
.
AlertStateOK
ctx
.
Firing
=
true
ctx
.
Rule
.
State
=
ctx
.
GetNewState
()
So
(
ctx
.
Rule
.
State
,
ShouldEqual
,
models
.
AlertStateAlerting
)
})
Convey
(
"ok -> error(alerting)"
,
func
()
{
ctx
.
PrevAlertState
=
models
.
AlertStateOK
ctx
.
Error
=
dummieError
ctx
.
Rule
.
ExecutionErrorState
=
models
.
ExecutionErrorSetAlerting
ctx
.
Rule
.
State
=
ctx
.
GetNewState
()
So
(
ctx
.
Rule
.
State
,
ShouldEqual
,
models
.
AlertStateAlerting
)
})
Convey
(
"ok -> error(keep_last)"
,
func
()
{
ctx
.
PrevAlertState
=
models
.
AlertStateOK
ctx
.
Error
=
dummieError
ctx
.
Rule
.
ExecutionErrorState
=
models
.
ExecutionErrorKeepState
ctx
.
Rule
.
State
=
ctx
.
GetNewState
()
So
(
ctx
.
Rule
.
State
,
ShouldEqual
,
models
.
AlertStateOK
)
})
Convey
(
"pending -> error(keep_last)"
,
func
()
{
ctx
.
PrevAlertState
=
models
.
AlertStatePending
ctx
.
Error
=
dummieError
ctx
.
Rule
.
ExecutionErrorState
=
models
.
ExecutionErrorKeepState
ctx
.
Rule
.
State
=
ctx
.
GetNewState
()
So
(
ctx
.
Rule
.
State
,
ShouldEqual
,
models
.
AlertStatePending
)
})
Convey
(
"ok -> no_data(alerting)"
,
func
()
{
ctx
.
PrevAlertState
=
models
.
AlertStateOK
ctx
.
Rule
.
NoDataState
=
models
.
NoDataSetAlerting
ctx
.
NoDataFound
=
true
ctx
.
Rule
.
State
=
ctx
.
GetNewState
()
So
(
ctx
.
Rule
.
State
,
ShouldEqual
,
models
.
AlertStateAlerting
)
})
Convey
(
"ok -> no_data(keep_last)"
,
func
()
{
ctx
.
PrevAlertState
=
models
.
AlertStateOK
ctx
.
Rule
.
NoDataState
=
models
.
NoDataKeepState
ctx
.
NoDataFound
=
true
ctx
.
Rule
.
State
=
ctx
.
GetNewState
()
So
(
ctx
.
Rule
.
State
,
ShouldEqual
,
models
.
AlertStateOK
)
})
Convey
(
"pending -> no_data(keep_last)"
,
func
()
{
ctx
.
PrevAlertState
=
models
.
AlertStatePending
ctx
.
Rule
.
NoDataState
=
models
.
NoDataKeepState
ctx
.
NoDataFound
=
true
ctx
.
Rule
.
State
=
ctx
.
GetNewState
()
So
(
ctx
.
Rule
.
State
,
ShouldEqual
,
models
.
AlertStatePending
)
})
Convey
(
"pending -> error(keep_last)"
,
func
()
{
ctx
.
PrevAlertState
=
models
.
AlertStatePending
ctx
.
Error
=
dummieError
ctx
.
Rule
.
ExecutionErrorState
=
models
.
ExecutionErrorKeepState
ctx
.
Rule
.
State
=
ctx
.
GetNewState
()
So
(
ctx
.
Rule
.
State
,
ShouldEqual
,
models
.
AlertStatePending
)
})
Convey
(
"ok -> no_data(alerting)"
,
func
()
{
ctx
.
PrevAlertState
=
models
.
AlertStateOK
ctx
.
Rule
.
NoDataState
=
models
.
NoDataSetAlerting
ctx
.
NoDataFound
=
true
ctx
.
Rule
.
State
=
ctx
.
GetNewState
()
So
(
ctx
.
Rule
.
State
,
ShouldEqual
,
models
.
AlertStateAlerting
)
})
Convey
(
"ok -> no_data(keep_last)"
,
func
()
{
ctx
.
PrevAlertState
=
models
.
AlertStateOK
ctx
.
Rule
.
NoDataState
=
models
.
NoDataKeepState
ctx
.
NoDataFound
=
true
ctx
.
Rule
.
State
=
ctx
.
GetNewState
()
So
(
ctx
.
Rule
.
State
,
ShouldEqual
,
models
.
AlertStateOK
)
})
Convey
(
"pending -> no_data(keep_last)"
,
func
()
{
ctx
.
PrevAlertState
=
models
.
AlertStatePending
ctx
.
Rule
.
NoDataState
=
models
.
NoDataKeepState
ctx
.
NoDataFound
=
true
ctx
.
Rule
.
State
=
ctx
.
GetNewState
()
So
(
ctx
.
Rule
.
State
,
ShouldEqual
,
models
.
AlertStatePending
)
})
})
}
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