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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
7cd9cdbe
Commit
7cd9cdbe
authored
Apr 02, 2019
by
Thong Kuah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor to share tests for base class method
DRY up tests for logging error.
parent
5eb2d6ea
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
75 additions
and
203 deletions
+75
-203
spec/services/clusters/applications/check_installation_progress_service_spec.rb
.../applications/check_installation_progress_service_spec.rb
+11
-16
spec/services/clusters/applications/install_service_spec.rb
spec/services/clusters/applications/install_service_spec.rb
+13
-63
spec/services/clusters/applications/patch_service_spec.rb
spec/services/clusters/applications/patch_service_spec.rb
+12
-62
spec/services/clusters/applications/upgrade_service_spec.rb
spec/services/clusters/applications/upgrade_service_spec.rb
+12
-62
spec/support/shared_examples/services/base_helm_service_shared_examples.rb
...ed_examples/services/base_helm_service_shared_examples.rb
+27
-0
No files found.
spec/services/clusters/applications/check_installation_progress_service_spec.rb
View file @
7cd9cdbe
...
@@ -33,15 +33,22 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
...
@@ -33,15 +33,22 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
end
end
end
end
shared_examples
'error
logg
ing'
do
shared_examples
'error
handl
ing'
do
context
'when installation raises a Kubeclient::HttpError'
do
context
'when installation raises a Kubeclient::HttpError'
do
let
(
:cluster
)
{
create
(
:cluster
,
:provided_by_user
,
:project
)
}
let
(
:cluster
)
{
create
(
:cluster
,
:provided_by_user
,
:project
)
}
let
(
:logger
)
{
service
.
send
(
:logger
)
}
let
(
:logger
)
{
service
.
send
(
:logger
)
}
let
(
:error
)
{
Kubeclient
::
HttpError
.
new
(
401
,
'Unauthorized'
,
nil
)
}
before
do
before
do
application
.
update!
(
cluster:
cluster
)
application
.
update!
(
cluster:
cluster
)
expect
(
service
).
to
receive
(
:installation_phase
).
and_raise
(
Kubeclient
::
HttpError
.
new
(
401
,
'Unauthorized'
,
nil
))
expect
(
service
).
to
receive
(
:installation_phase
).
and_raise
(
error
)
end
include_examples
'logs kubernetes errors'
do
let
(
:error_name
)
{
'Kubeclient::HttpError'
}
let
(
:error_message
)
{
'Unauthorized'
}
let
(
:error_code
)
{
401
}
end
end
it
'shows the response code from the error'
do
it
'shows the response code from the error'
do
...
@@ -50,18 +57,6 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
...
@@ -50,18 +57,6 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
expect
(
application
).
to
be_errored
.
or
(
be_update_errored
)
expect
(
application
).
to
be_errored
.
or
(
be_update_errored
)
expect
(
application
.
status_reason
).
to
eq
(
'Kubernetes error: 401'
)
expect
(
application
.
status_reason
).
to
eq
(
'Kubernetes error: 401'
)
end
end
it
'should log error'
do
expect
(
logger
).
to
receive
(
:error
)
service
.
execute
end
it
'logs error backtrace'
do
expect
(
logger
).
to
receive
(
:error
).
with
(
hash_including
(
backtrace:
instance_of
(
Array
)))
service
.
execute
end
end
end
end
end
...
@@ -73,7 +68,7 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
...
@@ -73,7 +68,7 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
context
'when application is updating'
do
context
'when application is updating'
do
let
(
:application
)
{
create
(
:clusters_applications_helm
,
:updating
)
}
let
(
:application
)
{
create
(
:clusters_applications_helm
,
:updating
)
}
include_examples
'error
logg
ing'
include_examples
'error
handl
ing'
RESCHEDULE_PHASES
.
each
{
|
phase
|
it_behaves_like
'a not yet terminated installation'
,
phase
}
RESCHEDULE_PHASES
.
each
{
|
phase
|
it_behaves_like
'a not yet terminated installation'
,
phase
}
...
@@ -134,7 +129,7 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
...
@@ -134,7 +129,7 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
end
end
context
'when application is installing'
do
context
'when application is installing'
do
include_examples
'error
logg
ing'
include_examples
'error
handl
ing'
RESCHEDULE_PHASES
.
each
{
|
phase
|
it_behaves_like
'a not yet terminated installation'
,
phase
}
RESCHEDULE_PHASES
.
each
{
|
phase
|
it_behaves_like
'a not yet terminated installation'
,
phase
}
...
...
spec/services/clusters/applications/install_service_spec.rb
View file @
7cd9cdbe
...
@@ -39,53 +39,34 @@ describe Clusters::Applications::InstallService do
...
@@ -39,53 +39,34 @@ describe Clusters::Applications::InstallService do
expect
(
helm_client
).
to
receive
(
:install
).
with
(
install_command
).
and_raise
(
error
)
expect
(
helm_client
).
to
receive
(
:install
).
with
(
install_command
).
and_raise
(
error
)
end
end
include_examples
'logs kubernetes errors'
do
let
(
:error_name
)
{
'Kubeclient::HttpError'
}
let
(
:error_message
)
{
'system failure'
}
let
(
:error_code
)
{
500
}
end
it
'make the application errored'
do
it
'make the application errored'
do
service
.
execute
service
.
execute
expect
(
application
).
to
be_errored
expect
(
application
).
to
be_errored
expect
(
application
.
status_reason
).
to
match
(
'Kubernetes error: 500'
)
expect
(
application
.
status_reason
).
to
match
(
'Kubernetes error: 500'
)
end
end
it
'logs errors'
do
expect
(
service
.
send
(
:logger
)).
to
receive
(
:error
).
with
(
{
exception:
'Kubeclient::HttpError'
,
message:
'system failure'
,
backtrace:
instance_of
(
Array
),
service:
'Clusters::Applications::InstallService'
,
app_id:
application
.
id
,
project_ids:
application
.
cluster
.
project_ids
,
group_ids:
[],
error_code:
500
}
)
expect
(
Gitlab
::
Sentry
).
to
receive
(
:track_acceptable_exception
).
with
(
error
,
extra:
hash_including
(
exception:
'Kubeclient::HttpError'
,
message:
'system failure'
,
backtrace:
instance_of
(
Array
),
service:
'Clusters::Applications::InstallService'
,
app_id:
application
.
id
,
project_ids:
application
.
cluster
.
project_ids
,
group_ids:
[],
error_code:
500
)
)
service
.
execute
end
end
end
context
'a non kubernetes error happens'
do
context
'a non kubernetes error happens'
do
let
(
:application
)
{
create
(
:clusters_applications_helm
,
:scheduled
)
}
let
(
:application
)
{
create
(
:clusters_applications_helm
,
:scheduled
)
}
let
(
:error
)
{
StandardError
.
new
(
"something bad happened"
)
}
let
(
:error
)
{
StandardError
.
new
(
'something bad happened'
)
}
before
do
before
do
expect
(
application
).
to
receive
(
:make_installing!
).
once
.
and_raise
(
error
)
expect
(
application
).
to
receive
(
:make_installing!
).
once
.
and_raise
(
error
)
end
end
include_examples
'logs kubernetes errors'
do
let
(
:error_name
)
{
'StandardError'
}
let
(
:error_message
)
{
'something bad happened'
}
let
(
:error_code
)
{
nil
}
end
it
'make the application errored'
do
it
'make the application errored'
do
expect
(
helm_client
).
not_to
receive
(
:install
)
expect
(
helm_client
).
not_to
receive
(
:install
)
...
@@ -94,37 +75,6 @@ describe Clusters::Applications::InstallService do
...
@@ -94,37 +75,6 @@ describe Clusters::Applications::InstallService do
expect
(
application
).
to
be_errored
expect
(
application
).
to
be_errored
expect
(
application
.
status_reason
).
to
eq
(
"Can't start installation process."
)
expect
(
application
.
status_reason
).
to
eq
(
"Can't start installation process."
)
end
end
it
'logs errors'
do
expect
(
service
.
send
(
:logger
)).
to
receive
(
:error
).
with
(
{
exception:
'StandardError'
,
error_code:
nil
,
message:
'something bad happened'
,
backtrace:
instance_of
(
Array
),
service:
'Clusters::Applications::InstallService'
,
app_id:
application
.
id
,
project_ids:
application
.
cluster
.
projects
.
pluck
(
:id
),
group_ids:
[]
}
)
expect
(
Gitlab
::
Sentry
).
to
receive
(
:track_acceptable_exception
).
with
(
error
,
extra:
hash_including
(
exception:
'StandardError'
,
error_code:
nil
,
message:
'something bad happened'
,
backtrace:
instance_of
(
Array
),
service:
'Clusters::Applications::InstallService'
,
app_id:
application
.
id
,
project_ids:
application
.
cluster
.
projects
.
pluck
(
:id
),
group_ids:
[]
)
)
service
.
execute
end
end
end
end
end
end
end
spec/services/clusters/applications/patch_service_spec.rb
View file @
7cd9cdbe
...
@@ -41,49 +41,30 @@ describe Clusters::Applications::PatchService do
...
@@ -41,49 +41,30 @@ describe Clusters::Applications::PatchService do
expect
(
helm_client
).
to
receive
(
:update
).
with
(
update_command
).
and_raise
(
error
)
expect
(
helm_client
).
to
receive
(
:update
).
with
(
update_command
).
and_raise
(
error
)
end
end
include_examples
'logs kubernetes errors'
do
let
(
:error_name
)
{
'Kubeclient::HttpError'
}
let
(
:error_message
)
{
'system failure'
}
let
(
:error_code
)
{
500
}
end
it
'make the application errored'
do
it
'make the application errored'
do
service
.
execute
service
.
execute
expect
(
application
).
to
be_update_errored
expect
(
application
).
to
be_update_errored
expect
(
application
.
status_reason
).
to
match
(
'Kubernetes error: 500'
)
expect
(
application
.
status_reason
).
to
match
(
'Kubernetes error: 500'
)
end
end
it
'logs errors'
do
expect
(
service
.
send
(
:logger
)).
to
receive
(
:error
).
with
(
{
exception:
'Kubeclient::HttpError'
,
message:
'system failure'
,
backtrace:
instance_of
(
Array
),
service:
'Clusters::Applications::PatchService'
,
app_id:
application
.
id
,
project_ids:
application
.
cluster
.
project_ids
,
group_ids:
[],
error_code:
500
}
)
expect
(
Gitlab
::
Sentry
).
to
receive
(
:track_acceptable_exception
).
with
(
error
,
extra:
{
exception:
'Kubeclient::HttpError'
,
message:
'system failure'
,
backtrace:
instance_of
(
Array
),
service:
'Clusters::Applications::PatchService'
,
app_id:
application
.
id
,
project_ids:
application
.
cluster
.
project_ids
,
group_ids:
[],
error_code:
500
}
)
service
.
execute
end
end
end
context
'a non kubernetes error happens'
do
context
'a non kubernetes error happens'
do
let
(
:application
)
{
create
(
:clusters_applications_knative
,
:scheduled
)
}
let
(
:application
)
{
create
(
:clusters_applications_knative
,
:scheduled
)
}
let
(
:error
)
{
StandardError
.
new
(
'something bad happened'
)
}
let
(
:error
)
{
StandardError
.
new
(
'something bad happened'
)
}
include_examples
'logs kubernetes errors'
do
let
(
:error_name
)
{
'StandardError'
}
let
(
:error_message
)
{
'something bad happened'
}
let
(
:error_code
)
{
nil
}
end
before
do
before
do
expect
(
application
).
to
receive
(
:make_updating!
).
once
.
and_raise
(
error
)
expect
(
application
).
to
receive
(
:make_updating!
).
once
.
and_raise
(
error
)
end
end
...
@@ -96,37 +77,6 @@ describe Clusters::Applications::PatchService do
...
@@ -96,37 +77,6 @@ describe Clusters::Applications::PatchService do
expect
(
application
).
to
be_update_errored
expect
(
application
).
to
be_update_errored
expect
(
application
.
status_reason
).
to
eq
(
"Can't start update process."
)
expect
(
application
.
status_reason
).
to
eq
(
"Can't start update process."
)
end
end
it
'logs errors'
do
expect
(
service
.
send
(
:logger
)).
to
receive
(
:error
).
with
(
{
exception:
'StandardError'
,
error_code:
nil
,
message:
'something bad happened'
,
backtrace:
instance_of
(
Array
),
service:
'Clusters::Applications::PatchService'
,
app_id:
application
.
id
,
project_ids:
application
.
cluster
.
projects
.
pluck
(
:id
),
group_ids:
[]
}
)
expect
(
Gitlab
::
Sentry
).
to
receive
(
:track_acceptable_exception
).
with
(
error
,
extra:
{
exception:
'StandardError'
,
error_code:
nil
,
message:
'something bad happened'
,
backtrace:
instance_of
(
Array
),
service:
'Clusters::Applications::PatchService'
,
app_id:
application
.
id
,
project_ids:
application
.
cluster
.
projects
.
pluck
(
:id
),
group_ids:
[]
}
)
service
.
execute
end
end
end
end
end
end
end
spec/services/clusters/applications/upgrade_service_spec.rb
View file @
7cd9cdbe
...
@@ -41,43 +41,18 @@ describe Clusters::Applications::UpgradeService do
...
@@ -41,43 +41,18 @@ describe Clusters::Applications::UpgradeService do
expect
(
helm_client
).
to
receive
(
:update
).
with
(
install_command
).
and_raise
(
error
)
expect
(
helm_client
).
to
receive
(
:update
).
with
(
install_command
).
and_raise
(
error
)
end
end
include_examples
'logs kubernetes errors'
do
let
(
:error_name
)
{
'Kubeclient::HttpError'
}
let
(
:error_message
)
{
'system failure'
}
let
(
:error_code
)
{
500
}
end
it
'make the application errored'
do
it
'make the application errored'
do
service
.
execute
service
.
execute
expect
(
application
).
to
be_update_errored
expect
(
application
).
to
be_update_errored
expect
(
application
.
status_reason
).
to
match
(
'Kubernetes error: 500'
)
expect
(
application
.
status_reason
).
to
match
(
'Kubernetes error: 500'
)
end
end
it
'logs errors'
do
expect
(
service
.
send
(
:logger
)).
to
receive
(
:error
).
with
(
{
exception:
'Kubeclient::HttpError'
,
message:
'system failure'
,
backtrace:
instance_of
(
Array
),
service:
'Clusters::Applications::UpgradeService'
,
app_id:
application
.
id
,
project_ids:
application
.
cluster
.
project_ids
,
group_ids:
[],
error_code:
500
}
)
expect
(
Gitlab
::
Sentry
).
to
receive
(
:track_acceptable_exception
).
with
(
error
,
extra:
{
exception:
'Kubeclient::HttpError'
,
message:
'system failure'
,
backtrace:
instance_of
(
Array
),
service:
'Clusters::Applications::UpgradeService'
,
app_id:
application
.
id
,
project_ids:
application
.
cluster
.
project_ids
,
group_ids:
[],
error_code:
500
}
)
service
.
execute
end
end
end
context
'a non kubernetes error happens'
do
context
'a non kubernetes error happens'
do
...
@@ -88,6 +63,12 @@ describe Clusters::Applications::UpgradeService do
...
@@ -88,6 +63,12 @@ describe Clusters::Applications::UpgradeService do
expect
(
application
).
to
receive
(
:make_updating!
).
once
.
and_raise
(
error
)
expect
(
application
).
to
receive
(
:make_updating!
).
once
.
and_raise
(
error
)
end
end
include_examples
'logs kubernetes errors'
do
let
(
:error_name
)
{
'StandardError'
}
let
(
:error_message
)
{
'something bad happened'
}
let
(
:error_code
)
{
nil
}
end
it
'make the application errored'
do
it
'make the application errored'
do
expect
(
helm_client
).
not_to
receive
(
:update
)
expect
(
helm_client
).
not_to
receive
(
:update
)
...
@@ -96,37 +77,6 @@ describe Clusters::Applications::UpgradeService do
...
@@ -96,37 +77,6 @@ describe Clusters::Applications::UpgradeService do
expect
(
application
).
to
be_update_errored
expect
(
application
).
to
be_update_errored
expect
(
application
.
status_reason
).
to
eq
(
"Can't start upgrade process."
)
expect
(
application
.
status_reason
).
to
eq
(
"Can't start upgrade process."
)
end
end
it
'logs errors'
do
expect
(
service
.
send
(
:logger
)).
to
receive
(
:error
).
with
(
{
exception:
'StandardError'
,
error_code:
nil
,
message:
'something bad happened'
,
backtrace:
instance_of
(
Array
),
service:
'Clusters::Applications::UpgradeService'
,
app_id:
application
.
id
,
project_ids:
application
.
cluster
.
projects
.
pluck
(
:id
),
group_ids:
[]
}
)
expect
(
Gitlab
::
Sentry
).
to
receive
(
:track_acceptable_exception
).
with
(
error
,
extra:
{
exception:
'StandardError'
,
error_code:
nil
,
message:
'something bad happened'
,
backtrace:
instance_of
(
Array
),
service:
'Clusters::Applications::UpgradeService'
,
app_id:
application
.
id
,
project_ids:
application
.
cluster
.
projects
.
pluck
(
:id
),
group_ids:
[]
}
)
service
.
execute
end
end
end
end
end
end
end
spec/support/shared_examples/services/base_helm_service_shared_examples.rb
0 → 100644
View file @
7cd9cdbe
# frozen_string_literal: true
shared_examples
'logs kubernetes errors'
do
let
(
:error_hash
)
do
{
exception:
error_name
,
message:
error_message
,
backtrace:
instance_of
(
Array
),
service:
service
.
class
.
name
,
app_id:
application
.
id
,
project_ids:
application
.
cluster
.
project_ids
,
group_ids:
[],
error_code:
error_code
}
end
it
'logs into kubernetes.log and Sentry'
do
expect
(
service
.
send
(
:logger
)).
to
receive
(
:error
).
with
(
error_hash
)
expect
(
Gitlab
::
Sentry
).
to
receive
(
:track_acceptable_exception
).
with
(
error
,
extra:
hash_including
(
error_hash
)
)
service
.
execute
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