Skip to content
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

Merged
merged 3 commits into from
Aug 15, 2017

Conversation

bmjen
Copy link
Contributor

@bmjen bmjen commented Aug 14, 2017

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

@bmjen
Copy link
Contributor Author

bmjen commented Aug 14, 2017

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.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.2%) to 92.474% when pulling 63093e3 on bmjen:validator-handling into 53436e1 on puppetlabs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 93.559% when pulling 73f3263 on bmjen:validator-handling into 53436e1 on puppetlabs:master.

@@ -25,17 +25,29 @@ def self.parse_targets(options)
options[:targets]
end

targets.map { |target|
skipped = []

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

target
else
skipped << target
next

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

report.add_event(
file: skipped_target,
source: name,
message: 'Target skipped. No files to validate.',

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)) }

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)
Copy link

@james-stocks james-stocks Aug 14, 2017

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'

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 )

Copy link
Contributor Author

@bmjen bmjen Aug 14, 2017

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'

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'

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

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(

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

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([])

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

Copy link

@james-stocks james-stocks left a 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

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 93.388% when pulling b6ad5ac on bmjen:validator-handling into 671df45 on puppetlabs:master.

@bmjen bmjen force-pushed the validator-handling branch 2 times, most recently from b997b67 to c366c2e Compare August 14, 2017 21:43
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 93.452% when pulling b997b67 on bmjen:validator-handling into 671df45 on puppetlabs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 93.452% when pulling c366c2e on bmjen:validator-handling into 671df45 on puppetlabs:master.

@bmjen bmjen changed the title (PDK-402, PDK-403, PDK-404) Update validators to handle targets better (PDK-401, PDK-402, PDK-403, PDK-404) Update validators to handle targets better Aug 14, 2017
@bmjen bmjen requested a review from austb August 14, 2017 21:52
targets, skipped, invalid = parse_targets(options)

process_skipped(skipped)
process_invalid(invalid)
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 good catch.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.03%) to 93.651% when pulling 534caaf on bmjen:validator-handling into 671df45 on puppetlabs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.03%) to 93.651% when pulling 2b2848b on bmjen:validator-handling into 671df45 on puppetlabs:master.

@austb austb dismissed james-stocks’s stale review August 15, 2017 01:34

Changes were implemented, and I like green.

james-stocks and others added 3 commits August 15, 2017 11:34
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.
@rodjek
Copy link
Contributor

rodjek commented Aug 15, 2017

Squashed the fixup commits into their counterparts

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.03%) to 93.671% when pulling b416c8e on bmjen:validator-handling into e0ec017 on puppetlabs:master.

@rodjek rodjek merged commit 407b70d into puppetlabs:master Aug 15, 2017
@bmjen bmjen deleted the validator-handling branch November 14, 2017 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants