From 94de52657c0cfff9bed312cffe78f9b59b9081d2 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 17 Feb 2009 18:07:27 -0600 Subject: The 'Environment' class can now calculate its modulepath. This includes adding PUPPETLIB from the shell environment. I'm moving responsibility for this from the Module class, because nearly every method in Puppet::Module accepted 'environment' as its argument, which is a good sign that it's on the wrong class. Signed-off-by: Luke Kanies --- spec/unit/node/environment.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'spec') 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 -- cgit