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
223d07b3
Commit
223d07b3
authored
Jun 05, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Environments#additional_metrics tests
parent
cf4aeafa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
133 additions
and
0 deletions
+133
-0
spec/controllers/projects/environments_controller_spec.rb
spec/controllers/projects/environments_controller_spec.rb
+40
-0
spec/models/environment_spec.rb
spec/models/environment_spec.rb
+93
-0
No files found.
spec/controllers/projects/environments_controller_spec.rb
View file @
223d07b3
...
...
@@ -311,6 +311,46 @@ describe Projects::EnvironmentsController do
end
end
describe
'GET #additional_metrics'
do
before
do
allow
(
controller
).
to
receive
(
:environment
).
and_return
(
environment
)
end
context
'when environment has no metrics'
do
before
do
expect
(
environment
).
to
receive
(
:additional_metrics
).
and_return
(
nil
)
end
context
'when requesting metrics as JSON'
do
it
'returns a metrics JSON document'
do
get
:additional_metrics
,
environment_params
(
format: :json
)
expect
(
response
).
to
have_http_status
(
204
)
expect
(
json_response
).
to
eq
({})
end
end
end
context
'when environment has some metrics'
do
before
do
expect
(
environment
).
to
receive
(
:additional_metrics
).
and_return
({
success:
true
,
data:
{},
last_update:
42
})
end
it
'returns a metrics JSON document'
do
get
:additional_metrics
,
environment_params
(
format: :json
)
expect
(
response
).
to
be_ok
expect
(
json_response
[
'success'
]).
to
be
(
true
)
expect
(
json_response
[
'data'
]).
to
eq
({})
expect
(
json_response
[
'last_update'
]).
to
eq
(
42
)
end
end
end
def
environment_params
(
opts
=
{})
opts
.
reverse_merge
(
namespace_id:
project
.
namespace
,
project_id:
project
,
...
...
spec/models/environment_spec.rb
View file @
223d07b3
...
...
@@ -409,6 +409,99 @@ describe Environment, models: true do
end
end
describe
'#has_metrics?'
do
subject
{
environment
.
has_metrics?
}
context
'when the enviroment is available'
do
context
'with a deployment service'
do
let
(
:project
)
{
create
(
:prometheus_project
)
}
context
'and a deployment'
do
let!
(
:deployment
)
{
create
(
:deployment
,
environment:
environment
)
}
it
{
is_expected
.
to
be_truthy
}
end
context
'but no deployments'
do
it
{
is_expected
.
to
be_falsy
}
end
end
context
'without a monitoring service'
do
it
{
is_expected
.
to
be_falsy
}
end
end
context
'when the environment is unavailable'
do
let
(
:project
)
{
create
(
:prometheus_project
)
}
before
do
environment
.
stop
end
it
{
is_expected
.
to
be_falsy
}
end
end
describe
'#additional_metrics'
do
let
(
:project
)
{
create
(
:prometheus_project
)
}
subject
{
environment
.
additional_metrics
}
context
'when the environment has additional metrics'
do
before
do
allow
(
environment
).
to
receive
(
:has_additional_metrics?
).
and_return
(
true
)
end
it
'returns the additional metrics from the deployment service'
do
expect
(
project
.
monitoring_service
).
to
receive
(
:reactive_query
)
.
with
(
Gitlab
::
Prometheus
::
Queries
::
AdditionalMetricsQuery
.
name
,
environment
.
id
)
.
and_return
(
:fake_metrics
)
is_expected
.
to
eq
(
:fake_metrics
)
end
end
context
'when the environment does not have metrics'
do
before
do
allow
(
environment
).
to
receive
(
:has_additional_metrics?
).
and_return
(
false
)
end
it
{
is_expected
.
to
be_nil
}
end
end
describe
'#has_additional_metrics??'
do
subject
{
environment
.
has_metrics?
}
context
'when the enviroment is available'
do
context
'with a deployment service'
do
let
(
:project
)
{
create
(
:prometheus_project
)
}
context
'and a deployment'
do
let!
(
:deployment
)
{
create
(
:deployment
,
environment:
environment
)
}
it
{
is_expected
.
to
be_truthy
}
end
context
'but no deployments'
do
it
{
is_expected
.
to
be_falsy
}
end
end
context
'without a monitoring service'
do
it
{
is_expected
.
to
be_falsy
}
end
end
context
'when the environment is unavailable'
do
let
(
:project
)
{
create
(
:prometheus_project
)
}
before
do
environment
.
stop
end
it
{
is_expected
.
to
be_falsy
}
end
end
describe
'#slug'
do
it
"is automatically generated"
do
expect
(
environment
.
slug
).
not_to
be_nil
...
...
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