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
0e0caf4d
Commit
0e0caf4d
authored
May 10, 2016
by
DJ Mountney
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for the health check feature
parent
160ef66d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
165 additions
and
0 deletions
+165
-0
app/views/admin/health_check/show.html.haml
app/views/admin/health_check/show.html.haml
+3
-0
spec/controllers/health_check_controller_spec.rb
spec/controllers/health_check_controller_spec.rb
+90
-0
spec/features/admin/admin_health_check_spec.rb
spec/features/admin/admin_health_check_spec.rb
+55
-0
spec/routing/admin_routing_spec.rb
spec/routing/admin_routing_spec.rb
+7
-0
spec/routing/routing_spec.rb
spec/routing/routing_spec.rb
+10
-0
No files found.
app/views/admin/health_check/show.html.haml
View file @
0e0caf4d
...
...
@@ -2,6 +2,9 @@
%h3
.page-title
Health Check
%p
.light
Access token is
%code
{
id
:'health-check-token'
}=
"
#{
current_application_settings
.
health_check_access_token
}
"
%p
.light
Health information can be reteived as plain text, json, or xml using:
%ul
...
...
spec/controllers/health_check_controller_spec.rb
0 → 100644
View file @
0e0caf4d
require
'spec_helper'
describe
HealthCheckController
do
let
(
:token
)
{
current_application_settings
.
health_check_access_token
}
let
(
:json_response
)
{
JSON
.
parse
(
response
.
body
)
}
let
(
:xml_response
)
{
Hash
.
from_xml
(
response
.
body
)[
'hash'
]
}
describe
'GET #index'
do
context
'when services are up but NO access token'
do
it
'returns a not found page'
do
get
:index
expect
(
response
).
to
be_not_found
end
end
context
'when services are up and an access token is provided'
do
it
'supports successful plaintest response'
do
get
:index
,
token:
token
expect
(
response
).
to
be_success
expect
(
response
.
content_type
).
to
eq
'text/plain'
end
it
'supports successful json response'
do
get
:index
,
token:
token
,
format: :json
expect
(
response
).
to
be_success
expect
(
response
.
content_type
).
to
eq
'application/json'
expect
(
json_response
[
'healthy'
]).
to
be
true
end
it
'supports successful xml response'
do
get
:index
,
token:
token
,
format: :xml
expect
(
response
).
to
be_success
expect
(
response
.
content_type
).
to
eq
'application/xml'
expect
(
xml_response
[
'healthy'
]).
to
be
true
end
it
'supports successful responses for specific checks'
do
get
:index
,
token:
token
,
checks:
'email'
,
format: :json
expect
(
response
).
to
be_success
expect
(
response
.
content_type
).
to
eq
'application/json'
expect
(
json_response
[
'healthy'
]).
to
be
true
end
end
context
'when a service is down but NO access token'
do
it
'returns a not found page'
do
get
:index
expect
(
response
).
to
be_not_found
end
end
context
'when a service is down and an access token is provided'
do
before
do
allow
(
HealthCheck
::
Utils
).
to
receive
(
:process_checks
).
with
(
'standard'
).
and_return
(
'The server is on fire'
)
allow
(
HealthCheck
::
Utils
).
to
receive
(
:process_checks
).
with
(
'email'
).
and_return
(
'Email is on fire'
)
end
it
'supports failure plaintest response'
do
get
:index
,
token:
token
expect
(
response
.
status
).
to
eq
(
500
)
expect
(
response
.
content_type
).
to
eq
'text/plain'
expect
(
response
.
body
).
to
include
(
'The server is on fire'
)
end
it
'supports failure json response'
do
get
:index
,
token:
token
,
format: :json
expect
(
response
.
status
).
to
eq
(
500
)
expect
(
response
.
content_type
).
to
eq
'application/json'
expect
(
json_response
[
'healthy'
]).
to
be
false
expect
(
json_response
[
'message'
]).
to
include
(
'The server is on fire'
)
end
it
'supports failure xml response'
do
get
:index
,
token:
token
,
format: :xml
expect
(
response
.
status
).
to
eq
(
500
)
expect
(
response
.
content_type
).
to
eq
'application/xml'
expect
(
xml_response
[
'healthy'
]).
to
be
false
expect
(
xml_response
[
'message'
]).
to
include
(
'The server is on fire'
)
end
it
'supports failure responses for specific checks'
do
get
:index
,
token:
token
,
checks:
'email'
,
format: :json
expect
(
response
.
status
).
to
eq
(
500
)
expect
(
response
.
content_type
).
to
eq
'application/json'
expect
(
json_response
[
'healthy'
]).
to
be
false
expect
(
json_response
[
'message'
]).
to
include
(
'Email is on fire'
)
end
end
end
end
spec/features/admin/admin_health_check_spec.rb
0 → 100644
View file @
0e0caf4d
require
'spec_helper'
feature
"Admin Health Check"
,
feature:
true
do
include
WaitForAjax
before
do
login_as
:admin
end
describe
'#show'
do
before
do
visit
admin_health_check_path
end
it
{
page
.
has_text?
'Health Check'
}
it
{
page
.
has_text?
'Health information can be reteived'
}
it
'has a health check access token'
do
token
=
current_application_settings
.
health_check_access_token
expect
(
page
).
to
have_content
(
"Access token is
#{
token
}
"
)
expect
(
page
).
to
have_selector
(
'#health-check-token'
,
text:
token
)
end
describe
'reload access token'
,
js:
true
do
it
'changes the access token'
do
orig_token
=
current_application_settings
.
health_check_access_token
click_button
'Reset health check access token'
wait_for_ajax
expect
(
find
(
'#health-check-token'
).
text
).
not_to
eq
orig_token
end
end
end
context
'when services are up'
do
before
do
visit
admin_health_check_path
end
it
'shows healthy status'
do
expect
(
page
).
to
have_content
(
'Current Status: Healthy'
)
end
end
context
'when a service is down'
do
before
do
allow
(
HealthCheck
::
Utils
).
to
receive
(
:process_checks
).
and_return
(
'The server is on fire'
)
visit
admin_health_check_path
end
it
'shows unhealthy status'
do
expect
(
page
).
to
have_content
(
'Current Status: Unhealthy'
)
expect
(
page
).
to
have_content
(
'The server is on fire'
)
end
end
end
spec/routing/admin_routing_spec.rb
View file @
0e0caf4d
...
...
@@ -118,3 +118,10 @@ describe Admin::DashboardController, "routing" do
expect
(
get
(
"/admin"
)).
to
route_to
(
'admin/dashboard#index'
)
end
end
# admin_health_check GET /admin/health_check(.:format) admin/health_check#show
describe
Admin
::
HealthCheckController
,
"routing"
do
it
"to #show"
do
expect
(
get
(
"/admin/health_check"
)).
to
route_to
(
'admin/health_check#show'
)
end
end
spec/routing/routing_spec.rb
View file @
0e0caf4d
...
...
@@ -243,3 +243,13 @@ describe "Groups", "routing" do
expect
(
get
(
'/1'
)).
to
route_to
(
'namespaces#show'
,
id:
'1'
)
end
end
describe
HealthCheckController
,
'routing'
do
it
'to #index'
do
expect
(
get
(
'/health_check'
)).
to
route_to
(
'health_check#index'
)
end
it
'also supports passing checks in the url'
do
expect
(
get
(
'/health_check/email'
)).
to
route_to
(
'health_check#index'
,
checks:
'email'
)
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