diff options
-rw-r--r-- | lib/puppet/util/autoload.rb | 9 | ||||
-rwxr-xr-x | spec/integration/util/autoload.rb | 18 | ||||
-rwxr-xr-x | spec/unit/util/autoload.rb | 20 |
3 files changed, 40 insertions, 7 deletions
diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb index b48e3afa1..ec2f48c7b 100644 --- a/lib/puppet/util/autoload.rb +++ b/lib/puppet/util/autoload.rb @@ -142,10 +142,11 @@ class Puppet::Util::Autoload end def module_directories - Puppet.settings.value(:modulepath, Puppet[:environment]).find_all do |dir| - FileTest.directory?(dir) - end.collect do |dir| - Dir.entries(dir) + # We have to require this late in the process because otherwise we might have + # load order issues. + require 'puppet/node/environment' + Puppet::Node::Environment.new.modulepath.collect do |dir| + Dir.entries(dir).reject { |f| f =~ /^\./ }.collect { |f| File.join(dir, f) } end.flatten.collect { |d| [File.join(d, "plugins"), File.join(d, "lib")] }.flatten.find_all do |d| FileTest.directory?(d) end diff --git a/spec/integration/util/autoload.rb b/spec/integration/util/autoload.rb index f84c00bcb..a1c8aaa58 100755 --- a/spec/integration/util/autoload.rb +++ b/spec/integration/util/autoload.rb @@ -3,6 +3,7 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } require 'puppet/util/autoload' +require 'fileutils' class AutoloadIntegrator @things = [] @@ -93,4 +94,21 @@ describe Puppet::Util::Autoload do } } end + + it "should be able to load files directly from modules" do + modulepath = tmpfile("autoload_module_testing") + libdir = File.join(modulepath, "mymod", "lib", "foo") + FileUtils.mkdir_p(libdir) + + file = File.join(libdir, "plugin.rb") + + Puppet[:modulepath] = modulepath + + with_loader("foo", "foo") do |dir, loader| + with_file(:plugin, file.split("/")) do + loader.load(:plugin) + loader.should be_loaded("plugin.rb") + end + end + end end diff --git a/spec/unit/util/autoload.rb b/spec/unit/util/autoload.rb index c4a8642a0..18938125d 100755 --- a/spec/unit/util/autoload.rb +++ b/spec/unit/util/autoload.rb @@ -22,9 +22,9 @@ describe Puppet::Util::Autoload do describe "when building the search path" do it "should collect all of the plugins and lib directories that exist in the current environment's module path" do Puppet.settings.expects(:value).with(:environment).returns "foo" - Puppet.settings.expects(:value).with(:modulepath, "foo").returns %w{/a /b /c} - Dir.expects(:entries).with("/a").returns %w{/a/one /a/two} - Dir.expects(:entries).with("/b").returns %w{/b/one /b/two} + Puppet.settings.expects(:value).with(:modulepath, :foo).returns "/a:/b:/c" + Dir.expects(:entries).with("/a").returns %w{one two} + Dir.expects(:entries).with("/b").returns %w{one two} FileTest.stubs(:directory?).returns false FileTest.expects(:directory?).with("/a").returns true @@ -36,6 +36,20 @@ describe Puppet::Util::Autoload do @autoload.module_directories.should == %w{/a/one/plugins /a/two/lib /b/one/plugins /b/two/lib} end + it "should not look for lib directories in directories starting with '.'" do + Puppet.settings.expects(:value).with(:environment).returns "foo" + Puppet.settings.expects(:value).with(:modulepath, :foo).returns "/a" + Dir.expects(:entries).with("/a").returns %w{. ..} + + FileTest.expects(:directory?).with("/a").returns true + FileTest.expects(:directory?).with("/a/./lib").never + FileTest.expects(:directory?).with("/a/./plugins").never + FileTest.expects(:directory?).with("/a/../lib").never + FileTest.expects(:directory?).with("/a/../plugins").never + + @autoload.module_directories + end + it "should include the module directories, the Puppet libdir, and all of the Ruby load directories" do @autoload.expects(:module_directories).returns %w{/one /two} @autoload.search_directories.should == ["/one", "/two", Puppet[:libdir], $:].flatten |