Skip to content

Commit

Permalink
(PDK-925) Exclude DEFAULT_IGNORED files from validator globbed targets
Browse files Browse the repository at this point in the history
  • Loading branch information
rodjek committed Oct 22, 2018
1 parent 71f9acf commit 974cb6c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lib/pdk/validate/base_validator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'pdk'
require 'pdk/cli/exec'
require 'pdk/module'

module PDK
module Validate
Expand Down Expand Up @@ -36,7 +37,6 @@ def self.parse_targets(options)
options[:targets]
end

fixtures_pattern = File.join('**', 'spec', 'fixtures', '**', '*')
targets.map! { |r| r.gsub(File::ALT_SEPARATOR, File::SEPARATOR) } if File::ALT_SEPARATOR
skipped = []
invalid = []
Expand All @@ -45,14 +45,15 @@ def self.parse_targets(options)
if File.directory?(target)
target_root = PDK::Util.module_root
pattern_glob = Array(pattern).map { |p| Dir.glob(File.join(target_root, p)) }
pattern_glob = pattern_glob.flatten.reject { |file| File.fnmatch(fixtures_pattern, file) }

target_list = pattern_glob.map do |file|
target_list = pattern_glob.flatten.map do |file|
if File.fnmatch(File.join(File.expand_path(target), '*'), file)
Pathname.new(file).relative_path_from(Pathname.new(PDK::Util.module_root)).to_s
end
end

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

skipped << target if target_list.flatten.empty?
target_list
elsif File.file?(target)
Expand Down
14 changes: 10 additions & 4 deletions spec/unit/pdk/validate/base_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,17 @@
end
end

context 'when the globbed files include spec/fixtures files' do
context 'when the globbed files include files matching the default ignore list' do
let(:targets) { [] }
let(:glob_pattern) { File.join(module_root, described_class.pattern) }
let(:files) { [File.join('manifests', 'init.pp')] }
let(:fixture_file) { File.join(module_root, 'spec', 'fixtures', 'test', 'manifests', 'init.pp') }
let(:fixture_file) { File.join(module_root, 'spec', 'fixtures', 'modules', 'test', 'manifests', 'init.pp') }
let(:pkg_file) { File.join(module_root, 'pkg', 'my-module-0.0.1', 'manifests', 'init.pp') }
let(:globbed_files) do
[
File.join(module_root, 'manifests', 'init.pp'),
fixture_file,
pkg_file,
]
end

Expand All @@ -116,8 +118,12 @@
allow(File).to receive(:expand_path).with(module_root).and_return(module_root)
end

it 'does not return the files under spec/fixtures' do
expect(target_files[0]).not_to include(fixture_file)
it 'does not return the files under spec/fixtures/' do
expect(target_files[0]).not_to include(a_string_including('spec/fixtures'))
end

it 'does not return the files under pkg/' do
expect(target_files[0]).not_to include(a_string_including('pkg/'))
end
end

Expand Down

0 comments on commit 974cb6c

Please sign in to comment.