diff options
author | Luke Kanies <luke@madstop.com> | 2009-02-17 17:55:57 -0600 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2009-02-18 22:38:45 -0600 |
commit | 2573ef1c4c2d472f9cf41ab3a1b67b7408d704b4 (patch) | |
tree | 56a20fea8bed3cf997bcf16fca5fbb98f0f66c9a | |
parent | 9c18d5aa4214f565b81b6cac07736fe072954bb1 (diff) | |
download | puppet-2573ef1c4c2d472f9cf41ab3a1b67b7408d704b4.tar.gz puppet-2573ef1c4c2d472f9cf41ab3a1b67b7408d704b4.tar.xz puppet-2573ef1c4c2d472f9cf41ab3a1b67b7408d704b4.zip |
Added support for finding modules from an environment
This uses the environment to search for the modules, rather
than relying on the Puppet::Module class to know how to
handle environments.
Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r-- | lib/puppet/node/environment.rb | 17 | ||||
-rwxr-xr-x | spec/unit/node/environment.rb | 38 |
2 files changed, 55 insertions, 0 deletions
diff --git a/lib/puppet/node/environment.rb b/lib/puppet/node/environment.rb index b64b9c2c4..d4c04469c 100644 --- a/lib/puppet/node/environment.rb +++ b/lib/puppet/node/environment.rb @@ -28,4 +28,21 @@ class Puppet::Node::Environment def initialize(name) @name = name end + + def module(name) + Puppet::Module.each_module(self[:modulepath]) do |mod| + return mod if mod.name == name + end + + return nil + end + + # Return all modules from this environment. + def modules + result = [] + Puppet::Module.each_module(self[:modulepath]) do |mod| + result << mod + end + result + end end diff --git a/spec/unit/node/environment.rb b/spec/unit/node/environment.rb index 48fe64280..0878a2a0c 100755 --- a/spec/unit/node/environment.rb +++ b/spec/unit/node/environment.rb @@ -33,5 +33,43 @@ describe Puppet::Node::Environment do env = Puppet::Node::Environment.new("testing") env["myvar"].should == "myval" end + + it "should be able to return its modules" do + Puppet::Node::Environment.new("testing").should respond_to(:modules) + end + + it "should return each module from the environment-specific module path when asked for its modules" do + env = Puppet::Node::Environment.new("testing") + module_path = %w{/one /two}.join(File::PATH_SEPARATOR) + env.expects(:[]).with(:modulepath).returns module_path + + Puppet::Module.expects(:each_module).with(module_path).multiple_yields("mod1", "mod2") + + env.modules.should == %w{mod1 mod2} + end + + it "should be able to return an individual module by matching the module name" do + env = Puppet::Node::Environment.new("testing") + module_path = %w{/one /two}.join(File::PATH_SEPARATOR) + env.expects(:[]).with(:modulepath).returns module_path + + one = stub 'one', :name => 'one' + two = stub 'two', :name => 'two' + Puppet::Module.expects(:each_module).with(module_path).multiple_yields(one, two) + + env.module("two").should equal(two) + end + + it "should return nil if asked for a module that is not in its path" do + env = Puppet::Node::Environment.new("testing") + module_path = %w{/one /two}.join(File::PATH_SEPARATOR) + env.expects(:[]).with(:modulepath).returns module_path + + one = stub 'one', :name => 'one' + two = stub 'two', :name => 'two' + Puppet::Module.expects(:each_module).with(module_path).multiple_yields(one, two) + + env.module("three").should be_nil + end end end |