Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

FACT-2650 Fix bug when loading external facts #543

Merged
merged 6 commits into from
Jun 9, 2020
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
2 changes: 2 additions & 0 deletions lib/custom_facts/util/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def load_all

paths = search_path
paths&.each do |dir|
# clean the search path of wrong slashes and backslashes
dir = dir.gsub(%r{[\/\\]+}, File::SEPARATOR)
# dir is already an absolute path
Dir.glob(File.join(dir, '*.rb')).each do |path|
# exclude dirs that end with .rb
Expand Down
18 changes: 18 additions & 0 deletions spec/custom_facts/util/loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,24 @@ def loader_from(places)
loader.load_all
loader.load_all
end

context 'when directory path has wrong slashes' do
before do
allow(Dir).to receive(:glob).with('/one/dir/*.rb').and_return %w[/one/dir/a.rb]
end

dir_paths = ['//one///dir', '//one///\\dir', '/one///\/\dir', '\one///\\dir']

dir_paths.each do |dir_path|
it 'corrects the directory path' do
allow(loader).to receive(:search_path).and_return [dir_path]

loader.load_all
Comment on lines +292 to +295
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no expect


expect(Dir).to have_received(:glob).with('/one/dir/*.rb')
end
end
end
end

it 'loads facts on the facter search path only once' do
Expand Down