diff options
| -rw-r--r-- | lib/puppet/node/environment.rb | 16 | ||||
| -rwxr-xr-x | spec/unit/node/environment.rb | 42 |
2 files changed, 58 insertions, 0 deletions
diff --git a/lib/puppet/node/environment.rb b/lib/puppet/node/environment.rb index d4c04469c..785a5ccec 100644 --- a/lib/puppet/node/environment.rb +++ b/lib/puppet/node/environment.rb @@ -37,6 +37,22 @@ class Puppet::Node::Environment return nil end + def modulepath + dirs = self[:modulepath].split(File::PATH_SEPARATOR) + if ENV["PUPPETLIB"] + dirs = ENV["PUPPETLIB"].split(File::PATH_SEPARATOR) + dirs + end + dirs.collect do |dir| + if dir !~ /^#{File::SEPARATOR}/ + File.join(Dir.getwd, dir) + else + dir + end + end.find_all do |p| + p =~ /^#{File::SEPARATOR}/ && FileTest.directory?(p) + end + end + # Return all modules from this environment. def modules result = [] diff --git a/spec/unit/node/environment.rb b/spec/unit/node/environment.rb index 0878a2a0c..855fd06ba 100755 --- a/spec/unit/node/environment.rb +++ b/spec/unit/node/environment.rb @@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/node/environment' +require 'puppet/util/execution' describe Puppet::Node::Environment do it "should use the default environment if no name is provided while initializing an environment" do @@ -18,6 +19,47 @@ describe Puppet::Node::Environment do Puppet::Node::Environment.new(:one).should equal(Puppet::Node::Environment.new("one")) end + it "should consider its module path to be the environment-specific modulepath setting" do + FileTest.stubs(:directory?).returns true + env = Puppet::Node::Environment.new("testing") + module_path = %w{/one /two}.join(File::PATH_SEPARATOR) + env.expects(:[]).with(:modulepath).returns module_path + + env.modulepath.should == %w{/one /two} + end + + it "should prefix the value of the 'PUPPETLIB' environment variable to the module path if present" do + FileTest.stubs(:directory?).returns true + Puppet::Util::Execution.withenv("PUPPETLIB" => %w{/l1 /l2}.join(File::PATH_SEPARATOR)) do + env = Puppet::Node::Environment.new("testing") + module_path = %w{/one /two}.join(File::PATH_SEPARATOR) + env.expects(:[]).with(:modulepath).returns module_path + + env.modulepath.should == %w{/l1 /l2 /one /two} + end + end + + it "should not return non-directories in the module path" do + env = Puppet::Node::Environment.new("testing") + module_path = %w{/one /two}.join(File::PATH_SEPARATOR) + env.expects(:[]).with(:modulepath).returns module_path + + FileTest.expects(:directory?).with("/one").returns true + FileTest.expects(:directory?).with("/two").returns false + + env.modulepath.should == %w{/one} + end + + it "should use the current working directory to fully-qualify unqualified paths" do + FileTest.stubs(:directory?).returns true + env = Puppet::Node::Environment.new("testing") + module_path = %w{/one two}.join(File::PATH_SEPARATOR) + env.expects(:[]).with(:modulepath).returns module_path + + two = File.join(Dir.getwd, "two") + env.modulepath.should == ["/one", two] + end + describe "when modeling a specific environment" do it "should have a method for returning the environment name" do Puppet::Node::Environment.new("testing").name.should == :testing |
