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
5f82d69d
Commit
5f82d69d
authored
Apr 02, 2019
by
rpereira2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add spec for RestClient raising exception
parent
53f1b231
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
47 deletions
+37
-47
spec/lib/gitlab/prometheus_client_spec.rb
spec/lib/gitlab/prometheus_client_spec.rb
+37
-47
No files found.
spec/lib/gitlab/prometheus_client_spec.rb
View file @
5f82d69d
...
...
@@ -270,7 +270,7 @@ describe Gitlab::PrometheusClient do
end
describe
'proxy'
do
context
'
query
'
do
context
'
get API
'
do
let
(
:prometheus_query
)
{
prometheus_cpu_query
(
'env-slug'
)
}
let
(
:query_url
)
{
prometheus_query_url
(
prometheus_query
)
}
...
...
@@ -278,58 +278,48 @@ describe Gitlab::PrometheusClient do
Timecop
.
freeze
{
example
.
run
}
end
it
'returns full response from the API call'
do
req_stub
=
stub_prometheus_request
(
query_url
,
body:
prometheus_value_body
(
'vector'
))
response
=
subject
.
proxy
(
'query'
,
{
query:
prometheus_query
})
json_response
=
JSON
.
parse
(
response
.
body
)
expect
(
response
.
code
).
to
eq
(
200
)
expect
(
json_response
).
to
eq
({
'status'
=>
'success'
,
'data'
=>
{
'resultType'
=>
'vector'
,
'result'
=>
[{
"metric"
=>
{},
"value"
=>
[
1488772511.004
,
"0.000041021495238095323"
]
}]
}
})
expect
(
req_stub
).
to
have_been_requested
context
'when response status code is 200'
do
it
'returns response object'
do
req_stub
=
stub_prometheus_request
(
query_url
,
body:
prometheus_value_body
(
'vector'
))
response
=
subject
.
proxy
(
'query'
,
{
query:
prometheus_query
})
json_response
=
JSON
.
parse
(
response
.
body
)
expect
(
response
.
code
).
to
eq
(
200
)
expect
(
json_response
).
to
eq
({
'status'
=>
'success'
,
'data'
=>
{
'resultType'
=>
'vector'
,
'result'
=>
[{
"metric"
=>
{},
"value"
=>
[
1488772511.004
,
"0.000041021495238095323"
]
}]
}
})
expect
(
req_stub
).
to
have_been_requested
end
end
end
context
'query_range
'
do
let
(
:prometheus_query
)
{
prometheus_memory_query
(
'env-slug'
)
}
let
(
:query_url
)
{
prometheus_query_range_url
(
prometheus_query
,
start:
2
.
hours
.
ago
)
}
context
'when response status code is not 200
'
do
it
'returns response object'
do
req_stub
=
stub_prometheus_request
(
query_url
,
status:
400
,
body:
{
error:
'error'
})
around
do
|
example
|
Timecop
.
freeze
{
example
.
run
}
response
=
subject
.
proxy
(
'query'
,
{
query:
prometheus_query
})
json_response
=
JSON
.
parse
(
response
.
body
)
expect
(
req_stub
).
to
have_been_requested
expect
(
response
.
code
).
to
eq
(
400
)
expect
(
json_response
).
to
eq
(
'error'
=>
'error'
)
end
end
it
'returns full response'
do
req_stub
=
stub_prometheus_request
(
query_url
,
body:
prometheus_values_body
(
'vector'
))
context
'when RestClient::Exception is raised'
do
before
do
stub_prometheus_request_with_exception
(
query_url
,
RestClient
::
Exception
)
end
response
=
subject
.
proxy
(
'query_range'
,
{
query:
prometheus_query
,
start:
2
.
hours
.
ago
.
to_f
,
end:
Time
.
now
.
to_f
,
step:
60
})
json_response
=
JSON
.
parse
(
response
.
body
)
expect
(
response
.
code
).
to
eq
(
200
)
expect
(
json_response
).
to
eq
({
"status"
=>
"success"
,
"data"
=>
{
"resultType"
=>
"vector"
,
"result"
=>
[{
"metric"
=>
{},
"values"
=>
[
[
1488758662.506
,
"0.00002996364761904785"
],
[
1488758722.506
,
"0.00003090239047619091"
]
]
}]
}
})
expect
(
req_stub
).
to
have_been_requested
it
'raises PrometheusClient::Error'
do
expect
{
subject
.
proxy
(
'query'
,
{
query:
prometheus_query
})
}.
to
(
raise_error
(
Gitlab
::
PrometheusClient
::
Error
,
'Network connection error'
)
)
end
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