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-925) Exclude files that wouldn't be packaged from being validated #578

Merged
merged 2 commits into from
Oct 24, 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
20 changes: 20 additions & 0 deletions lib/pdk/module.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'pathspec'

module PDK
module Module
DEFAULT_IGNORED = [
'/pkg/',
'.*',
'~*',
'/coverage',
'/checksums.json',
'/REVISION',
'/spec/fixtures/modules/',
].freeze

def default_ignored_pathspec
@default_ignored_pathspec ||= PathSpec.new(DEFAULT_IGNORED)
end
module_function :default_ignored_pathspec
end
end
13 changes: 2 additions & 11 deletions lib/pdk/module/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,12 @@
require 'zlib'
require 'pathspec'
require 'find'
require 'pdk/module'
require 'pdk/tests/unit'

module PDK
module Module
class Build
DEFAULT_IGNORED = [
'/pkg/',
'.*',
'~*',
'/coverage',
'/checksums.json',
'/REVISION',
'/spec/fixtures/modules/',
].freeze

def self.invoke(options = {})
new(options).build
end
Expand Down Expand Up @@ -213,7 +204,7 @@ def ignored_files
ignored = ignored.add("\/#{File.basename(target_dir)}\/")
end

DEFAULT_IGNORED.each { |r| ignored.add(r) }
PDK::Module::DEFAULT_IGNORED.each { |r| ignored.add(r) }

ignored
end
Expand Down
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