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-1194) Exclude plans/**/*.pp from PDK::Validate::PuppetSyntax #586

Merged
merged 2 commits into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/pdk/validate/base_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def self.parse_targets(options)
end
end

target_list = target_list.reject { |file| PDK::Module.default_ignored_pathspec.match(file) }
ignore_list = ignore_pathspec
target_list = target_list.reject { |file| ignore_list.match(file) }

skipped << target if target_list.flatten.empty?
target_list
Expand All @@ -76,6 +77,18 @@ def self.parse_targets(options)
[matched, skipped, invalid]
end

def self.ignore_pathspec
ignore_pathspec = PDK::Module.default_ignored_pathspec.dup

if respond_to?(:pattern_ignore)
Array(pattern_ignore).each do |pattern|
ignore_pathspec.add(pattern)
end
end

ignore_pathspec
end

def self.parse_options(_options, targets)
targets
end
Expand Down
4 changes: 4 additions & 0 deletions lib/pdk/validate/puppet/puppet_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def self.pattern
'**/**.pp'
end

def self.pattern_ignore
'/plans/**/*.pp'
end

def self.spinner_text(_targets = nil)
_('Checking Puppet manifest syntax (%{pattern}).') % { pattern: pattern }
end
Expand Down
27 changes: 27 additions & 0 deletions spec/unit/pdk/validate/puppet_syntax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,33 @@

it_behaves_like 'it accepts .pp targets'

describe '.parse_targets' do
context 'when the module contains task .pp files' do
subject(:parsed_targets) { described_class.parse_targets(targets: targets) }

before(:each) do
allow(Dir).to receive(:glob).with(any_args).and_call_original
allow(Dir).to receive(:glob).with(glob_pattern).and_return(globbed_files)
allow(File).to receive(:expand_path).with(any_args).and_call_original
allow(File).to receive(:expand_path).with(module_root).and_return(module_root)
end

let(:targets) { [] }
let(:glob_pattern) { File.join(module_root, described_class.pattern) }
let(:globbed_files) do
[
File.join(module_root, 'manifests', 'init.pp'),
File.join(module_root, 'plans', 'foo.pp'),
File.join(module_root, 'plans', 'nested', 'thing.pp'),
]
end

it 'does not include the task .pp files in the return value' do
expect(parsed_targets.first).to eq([File.join('manifests', 'init.pp')])
end
end
end

describe '.parse_options' do
subject(:command_args) { described_class.parse_options(options, targets) }

Expand Down