Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
a53b36e3
Commit
a53b36e3
authored
Sep 05, 2018
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve PrometheusAlert EE validation
parent
2a209048
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
10 deletions
+43
-10
ee/spec/models/prometheus_alert_spec.rb
ee/spec/models/prometheus_alert_spec.rb
+43
-10
No files found.
ee/spec/models/prometheus_alert_spec.rb
View file @
a53b36e3
require
'spec_helper'
describe
PrometheusAlert
do
let
(
:metric
)
{
create
(
:prometheus_metric
)
}
set
(
:project
)
{
build
(
:project
)
}
let
(
:metric
)
{
build
(
:prometheus_metric
)
}
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:environment
)
}
end
describe
'project validations'
do
let
(
:environment
)
{
build
(
:environment
,
project:
project
)
}
let
(
:metric
)
{
build
(
:prometheus_metric
,
project:
project
)
}
subject
do
build
(
:prometheus_alert
,
prometheus_metric:
metric
,
environment:
environment
,
project:
project
)
end
context
'when environment and metric belongs same project'
do
it
{
is_expected
.
to
be_valid
}
end
context
'when environment belongs to different project'
do
let
(
:environment
)
{
build
(
:environment
)
}
it
{
is_expected
.
not_to
be_valid
}
end
context
'when metric belongs to different project'
do
let
(
:metric
)
{
build
(
:prometheus_metric
)
}
it
{
is_expected
.
not_to
be_valid
}
end
context
'when metric is common'
do
let
(
:metric
)
{
build
(
:prometheus_metric
,
:common
)
}
it
{
is_expected
.
to
be_valid
}
end
end
describe
'#full_query'
do
it
'returns the concatenated query'
do
before
do
subject
.
operator
=
"gt"
subject
.
threshold
=
1
subject
.
prometheus_metric_id
=
metric
.
id
subject
.
prometheus_metric
=
metric
end
it
'returns the concatenated query'
do
expect
(
subject
.
full_query
).
to
eq
(
"
#{
metric
.
query
}
> 1.0"
)
end
end
describe
'#to_param'
do
it
'returns the params of the prometheus alert'
do
before
do
subject
.
operator
=
"gt"
subject
.
threshold
=
1
subject
.
prometheus_metric_id
=
metric
.
id
subject
.
prometheus_metric
=
metric
end
alert_params
=
{
it
'returns the params of the prometheus alert'
do
expect
(
subject
.
to_param
).
to
eq
(
"alert"
=>
metric
.
title
,
"expr"
=>
"
#{
metric
.
query
}
> 1.0"
,
"for"
=>
"5m"
,
"labels"
=>
{
"gitlab"
=>
"hook"
,
"gitlab_alert_id"
=>
metric
.
id
}
}
expect
(
subject
.
to_param
).
to
eq
(
alert_params
)
})
end
end
end
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