summaryrefslogtreecommitdiffstats
path: root/spec/unit/node
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-02-17 18:07:27 -0600
committerLuke Kanies <luke@madstop.com>2009-02-18 22:38:45 -0600
commit94de52657c0cfff9bed312cffe78f9b59b9081d2 (patch)
tree5800599be24e403ef4a8accf9a435aefcc814471 /spec/unit/node
parent2573ef1c4c2d472f9cf41ab3a1b67b7408d704b4 (diff)
downloadpuppet-94de52657c0cfff9bed312cffe78f9b59b9081d2.tar.gz
puppet-94de52657c0cfff9bed312cffe78f9b59b9081d2.tar.xz
puppet-94de52657c0cfff9bed312cffe78f9b59b9081d2.zip
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 <luke@madstop.com>
Diffstat (limited to 'spec/unit/node')
-rwxr-xr-xspec/unit/node/environment.rb42
1 files changed, 42 insertions, 0 deletions
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