diff options
author | Rick Bradley <rick@rickbradley.com> | 2010-12-12 20:10:53 -0600 |
---|---|---|
committer | Daniel Pittman <daniel@rimspace.net> | 2011-01-31 11:23:58 -0800 |
commit | b88a088c6e53ef96914280e6937b9b9214b6c64b (patch) | |
tree | 6c07ee88a921caee62d88e3a0bb8cdcb3efbdeed /spec | |
parent | d9b8f2ad68626b8655d98a8d9037283f671f86bb (diff) | |
download | facter-b88a088c6e53ef96914280e6937b9b9214b6c64b.tar.gz facter-b88a088c6e53ef96914280e6937b9b9214b6c64b.tar.xz facter-b88a088c6e53ef96914280e6937b9b9214b6c64b.zip |
(#5510) Facter should load custom fact definitions in filename order.
Ruby's Dir.entries will return files in different orders depending on
the OS and/or filesystem. As a result Facter::Util::Loader will load
ruby custom fact definitions in different orders on different platforms.
Specs to expose the bugs, and code to ensure that custom fact files are
loaded in alphabetical order.
Addresses redmine issue #5510
http://projects.puppetlabs.com/issues/5510
Signed-off-by: Rick Bradley <rick@rickbradley.com>
Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/unit/util/loader_spec.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/unit/util/loader_spec.rb b/spec/unit/util/loader_spec.rb index 0bb823e..eed533a 100755 --- a/spec/unit/util/loader_spec.rb +++ b/spec/unit/util/loader_spec.rb @@ -4,6 +4,20 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/loader' + +# loader subclass for making assertions about file/directory ordering +class TestLoader < Facter::Util::Loader + def loaded_files + @loaded_files ||= [] + end + + def load_file(file) + loaded_files << file + super + end +end + + describe Facter::Util::Loader do def with_env(values) old = {} @@ -96,6 +110,21 @@ describe Facter::Util::Loader do @loader.load(:testing) end + it 'should load any ruby files in directories matching the fact name in the search path in sorted order regardless of the order returned by Dir.entries' do + @loader = TestLoader.new + + @loader.stubs(:search_path).returns %w{/one/dir} + FileTest.stubs(:exist?).returns false + FileTest.stubs(:directory?).with("/one/dir/testing").returns true + @loader.stubs(:search_path).returns %w{/one/dir} + + Dir.stubs(:entries).with("/one/dir/testing").returns %w{foo.rb bar.rb} + %w{/one/dir/testing/foo.rb /one/dir/testing/bar.rb}.each { |f| File.stubs(:directory?).with(f).returns false } + + @loader.load(:testing) + @loader.loaded_files.should == %w{/one/dir/testing/bar.rb /one/dir/testing/foo.rb} + end + it "should load any ruby files in directories matching the fact name in the search path" do @loader.expects(:search_path).returns %w{/one/dir} FileTest.stubs(:exist?).returns false @@ -166,6 +195,20 @@ describe Facter::Util::Loader do @loader.load_all end + it 'should load all files in sorted order for any given directory regardless of the order returned by Dir.entries' do + @loader = TestLoader.new + + @loader.stubs(:search_path).returns %w{/one/dir} + Dir.stubs(:entries).with("/one/dir").returns %w{foo.rb bar.rb} + + %w{/one/dir}.each { |f| File.stubs(:directory?).with(f).returns true } + %w{/one/dir/foo.rb /one/dir/bar.rb}.each { |f| File.stubs(:directory?).with(f).returns false } + + @loader.load_all + + @loader.loaded_files.should == %w{/one/dir/bar.rb /one/dir/foo.rb} + end + it "should not load files in the util subdirectory" do @loader.expects(:search_path).returns %w{/one/dir} |