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

(SDK-296) Allow target selection for the metadata validator #124

Merged
merged 2 commits into from
Jul 5, 2017

Conversation

rodjek
Copy link
Contributor

@rodjek rodjek commented Jun 30, 2017

In order to accommodate this functionality, I needed to refactor the base validator a bit so that we can optionally invoke the validator once per target (as metadata-json-lint only supports testing a single file).

@rodjek rodjek added the feature label Jun 30, 2017
@@ -70,4 +70,71 @@
end
end
end

context 'when validating a specific file' do
include_context 'in a new module', 'foo'

Choose a reason for hiding this comment

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

Due to SDK-294 (an intermittent bug when re-using the foo folder on Windows) it's preferable to give each feature its own test module name instead of always using 'foo'

c.context = :module
c.add_spinner(spinner_text)
end
targets = (self::INVOKE_STYLE == :per_target) ? targets.combination(1).to_a : Array[targets]
Copy link

@james-stocks james-stocks Jul 4, 2017

Choose a reason for hiding this comment

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

I needed to try this out in IRB for myself to understand what it's doing: the former case gives an array of targets; the latter case wraps the targets in an 'outer array' that means targets.each will return the targets array as a single value.

Is the the combination(1).to_a actually needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this is to try and avoid duplicating the logic below when handling the different invoke styles. If :per_target, we take the array of targets and using Array#combination, split it into a 2 dimensional array, where each element inside targets is itself an array of 1 target.

Given

targets = [
  'target1',
  'target2',
  'target3',
]

If the INVOKE_STYLE is :per_target, the targets array becomes [['target1'], ['target2'], ['target3']]. If the INVOKE_STYLE is :once, the targets array becomes [['target1', 'target2', 'target3']].

By doing it this way, we ensure that targets will always be an array of arrays and just loop through it and avoid having to put a conditional around the execution logic to determine if how many times the validated should be invoked and with which targets.

Choose a reason for hiding this comment

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

👍

@@ -4,6 +4,8 @@
module PDK
module Validate
class BaseValidator
INVOKE_STYLE = :once

Choose a reason for hiding this comment

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

I'm unsure if the intention of :once is immediately understandable - might :combined or :all_targets be more immediately understandable?
Or leave it as :once but add some commenting here on the possible values of INVOKE_STYLE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 That constant definitely needs some documentation.

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.

Couple of comments on things I'm unsure of

@@ -4,6 +4,14 @@
module PDK
module Validate
class BaseValidator
# Controls how many times the validator is invoked.

Choose a reason for hiding this comment

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

👍

@james-stocks james-stocks merged commit d291a6a into puppetlabs:master Jul 5, 2017
@rodjek rodjek deleted the sdk-296 branch July 5, 2017 23:35
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.

2 participants