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
706d49b2
Commit
706d49b2
authored
Sep 04, 2017
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added dynamic skip reason to SystemCheck
parent
6c21e6f9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
3 deletions
+44
-3
lib/system_check/base_check.rb
lib/system_check/base_check.rb
+19
-0
lib/system_check/simple_executor.rb
lib/system_check/simple_executor.rb
+2
-2
spec/lib/system_check/simple_executor_spec.rb
spec/lib/system_check/simple_executor_spec.rb
+23
-1
No files found.
lib/system_check/base_check.rb
View file @
706d49b2
...
...
@@ -62,6 +62,25 @@ module SystemCheck
call_or_return
(
@skip_reason
)
||
'skipped'
end
# Define a reason why we skipped the SystemCheck (during runtime)
#
# This is used when you need dynamic evaluation like when you have
# multiple reasons why a check can fail
#
# @param [String] reason to be displayed
def
skip_reason
=
(
reason
)
@skip_reason
=
reason
end
# Skip reason defined during runtime
#
# This value have precedence over the one defined in the subclass
#
# @return [String] the reason
def
skip_reason
@skip_reason
end
# Does the check support automatically repair routine?
#
# @return [Boolean] whether check implemented `#repair!` method or not
...
...
lib/system_check/simple_executor.rb
View file @
706d49b2
...
...
@@ -23,7 +23,7 @@ module SystemCheck
#
# @param [BaseCheck] check class
def
<<
(
check
)
raise
ArgumentError
unless
check
<
BaseCheck
raise
ArgumentError
unless
check
.
is_a?
(
Class
)
&&
check
<
BaseCheck
@checks
<<
check
end
...
...
@@ -48,7 +48,7 @@ module SystemCheck
# When implements skip method, we run it first, and if true, skip the check
if
check
.
can_skip?
&&
check
.
skip?
$stdout
.
puts
check_klass
.
skip_reason
.
color
(
:magenta
)
$stdout
.
puts
check
.
skip_reason
.
try
(
:color
,
:magenta
)
||
check
_klass
.
skip_reason
.
color
(
:magenta
)
return
end
...
...
spec/lib/system_check/simple_executor_spec.rb
View file @
706d49b2
...
...
@@ -35,6 +35,20 @@ describe SystemCheck::SimpleExecutor do
end
end
class
DynamicSkipCheck
<
SystemCheck
::
BaseCheck
set_name
'dynamic skip check'
set_skip_reason
'this is a skip reason'
def
skip?
self
.
skip_reason
=
'this is a dynamic skip reason'
true
end
def
check?
raise
'should not execute this'
end
end
class
MultiCheck
<
SystemCheck
::
BaseCheck
set_name
'multi check'
...
...
@@ -127,6 +141,10 @@ describe SystemCheck::SimpleExecutor do
expect
(
subject
.
checks
.
size
).
to
eq
(
1
)
end
it
'errors out when passing multiple items'
do
expect
{
subject
<<
[
SimpleCheck
,
OtherCheck
]
}.
to
raise_error
(
ArgumentError
)
end
end
subject
{
described_class
.
new
(
'Test'
)
}
...
...
@@ -205,10 +223,14 @@ describe SystemCheck::SimpleExecutor do
subject
.
run_check
(
SkipCheck
)
end
it
'displays
#
skip_reason'
do
it
'displays
.
skip_reason'
do
expect
{
subject
.
run_check
(
SkipCheck
)
}.
to
output
(
/this is a skip reason/
).
to_stdout
end
it
'displays #skip_reason'
do
expect
{
subject
.
run_check
(
DynamicSkipCheck
)
}.
to
output
(
/this is a dynamic skip reason/
).
to_stdout
end
it
'does not execute #check when #skip? is true'
do
expect_any_instance_of
(
SkipCheck
).
not_to
receive
(
:check?
)
...
...
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