-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(PDK-401, PDK-402, PDK-403, PDK-404) Update validators to handle targets better #248
Conversation
I'll need to add some test coverage to the spec and acceptance tests. Will also need to integrate with @james-stocks 's metadata changes to complete the UX improvements on validation target handling. |
63093e3
to
73f3263
Compare
@@ -25,17 +25,29 @@ def self.parse_targets(options) | |||
options[:targets] | |||
end | |||
|
|||
targets.map { |target| | |||
skipped = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to add yardoc to describe what the method now returns; and also to briefly explain what skipped and invalid mean
lib/pdk/validators/base_validator.rb
Outdated
target | ||
else | ||
skipped << target | ||
next |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this next
needed? It looks like there's only end
lines below it
lib/pdk/validators/base_validator.rb
Outdated
report.add_event( | ||
file: skipped_target, | ||
source: name, | ||
message: 'Target skipped. No files to validate.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the code above; I believe that skipped means that the file/directory given by the user as a target does exist on the filesystem, but does not match the pattern built into the validator.
I'm not sure this message conveys that. And 'No files to validate' might be confusing if other targets in the command did have valid targets.
message: 'Target was skipped as it does not match the validator\'s pattern'
?
if respond_to?(:pattern) | ||
if File.directory?(target) | ||
Array[pattern].flatten.map { |p| Dir.glob(File.join(target, p)) } | ||
target_list = Array[pattern].flatten.map { |p| Dir.glob(File.join(target, p)) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point if the target directory contains a mixture of file types; we glob those that match the pattern and ignore those that don't.
We don't report those unmatching files as skipped... I think that's OK.
@@ -42,7 +42,7 @@ def self.stop_spinner(exit_code) | |||
end | |||
|
|||
def self.invoke(report, options = {}) | |||
targets = parse_targets(options) | |||
targets, _skipped, _invalid = parse_targets(options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class's invoke method does not report on _skipped
or _invalid
and doesn't seem to call super.invoke
- should reporting of skipped and invalid targets be added?
@@ -16,8 +16,12 @@ def self.cmd | |||
'rubocop' | |||
end | |||
|
|||
def self.pattern | |||
'**/**.rb' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rubocop checks a number of different files e.g. .irbrc, Rakefile, Gemfile - should this pattern definitely restrict to *.rb ?
I think for a Puppet module we want {Rakefile,Gemfile,**/**.rb}
(or whatever the glob syntax for or is )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently we have Gemfile
and Rakefile
excluded in .rubocop.yml
. I don't think there are anymore ruby files that don't end in .rb
we need to worry about.
@@ -11,7 +11,7 @@ def self.name | |||
end | |||
|
|||
def self.pattern | |||
'metadata.json' | |||
'**/metadata.json' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PDK-401 specifies Only validate <module_root>/metadata.json so I think this pattern should be unchanged.
@@ -26,7 +26,7 @@ def self.spinner_text(targets = []) | |||
end | |||
|
|||
def self.pattern | |||
'metadata.json' | |||
'**/metadata.json' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PDK-401 specifies Only validate <module_root>/metadata.json so I think this pattern should be unchanged.
@@ -100,7 +100,7 @@ | |||
end | |||
|
|||
its(:stdout) do | |||
is_expected.to have_junit_testcase.in_testsuite('metadata-json-lint').with_attributes( | |||
is_expected.not_to have_junit_testcase.in_testsuite('metadata-json-lint').with_attributes( | |||
'classname' => 'metadata-json-lint.dependencies', | |||
'name' => 'broken.json', | |||
).that_failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.that_failed can be removed now that we're asserting the testcase does not exist
@@ -100,7 +100,7 @@ | |||
end | |||
|
|||
its(:stdout) do | |||
is_expected.to have_junit_testcase.in_testsuite('metadata-json-lint').with_attributes( | |||
is_expected.not_to have_junit_testcase.in_testsuite('metadata-json-lint').with_attributes( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May now want to assert that metadata.json was included in the test results
end | ||
end | ||
end | ||
|
||
context 'when given specific target files' do | ||
context 'when given unmatched target files' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I'd understand this immediately when reading.
Perhaps
context 'when given unmatching target files' do
or
context 'when given a target that will not match the validator\s pattern' do
?
it 'returns the targets' do | ||
expect(parsed_targets).to eq(targets) | ||
it 'skips the targets' do | ||
expect(parsed_targets.first).to eq([]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be valuable to also put an expectation on the skipped and invalid values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a number of comments. The one I'd request a change on is where the **/metadata.json pattern is being used - PDK-401 specifies that we only validate {module_root}/metadata.json
21b03b6
to
b6ad5ac
Compare
b997b67
to
c366c2e
Compare
targets, skipped, invalid = parse_targets(options) | ||
|
||
process_skipped(skipped) | ||
process_invalid(invalid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to pass the report object here. process_skipped(report, skipped)
and process_invalid(report, invalid)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 good catch.
Changes were implemented, and I like green.
Only check metadata.json. If the user passes targets through the CLI, inform user they are being ignored.
Updates validators to handle targets consistently and disallows input of explicit targets that are incompatible with the validator's defined filter pattern. Also updates the spinner text to be informative about what kind of files the validator is validating against.
2b2848b
to
b416c8e
Compare
Squashed the fixup commits into their counterparts |
Updates validators to handle targets consistently and disallows input of
explicit targets that are incompatible with the validator's defined
filter pattern. Also updates the spinner text to be informative about what
kind of files the validator is validating against.
Relates to #239