diff options
author | Michael V. O'Brien <michael@reductivelabs.com> | 2007-10-03 17:09:06 -0500 |
---|---|---|
committer | Michael V. O'Brien <michael@reductivelabs.com> | 2007-10-03 17:09:06 -0500 |
commit | 35033ba63222e8d731823b4f4f722fa731ef70a5 (patch) | |
tree | e8bdb81397d2d3e577107f4f359a01077dc31ba0 | |
parent | 0b8893b3b8ffd391287a590b4f271edca70331da (diff) | |
parent | b727a95aa4b72ce057653101cf1f50fa49c4b0a8 (diff) | |
download | puppet-35033ba63222e8d731823b4f4f722fa731ef70a5.tar.gz puppet-35033ba63222e8d731823b4f4f722fa731ef70a5.tar.xz puppet-35033ba63222e8d731823b4f4f722fa731ef70a5.zip |
Merge branch 'master' of git://reductivelabs.com/puppet
-rw-r--r-- | lib/puppet/module.rb | 13 | ||||
-rwxr-xr-x | spec/unit/other/modules.rb | 51 |
2 files changed, 49 insertions, 15 deletions
diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb index dc30d8167..45860c74d 100644 --- a/lib/puppet/module.rb +++ b/lib/puppet/module.rb @@ -27,8 +27,8 @@ class Puppet::Module return nil end - modpath = modulepath(environment).collect { |p| - File::join(p, modname) + modpath = modulepath(environment).collect { |path| + File::join(path, modname) }.find { |f| File::directory?(f) } return nil unless modpath @@ -72,10 +72,9 @@ class Puppet::Module # Otherwise, try to find manifests matching +pat+ relative to +cwd+ def self.find_manifests(start, options = {}) cwd = options[:cwd] || Dir.getwd - path, pat = split_path(start) - mod = find(path, options[:environment]) - if mod - return mod.manifests(pat) + module_name, pattern = split_path(start) + if module_name and mod = find(module_name, options[:environment]) + return mod.manifests(pattern) else abspat = File::expand_path(start, cwd) files = Dir.glob(abspat).reject { |f| FileTest.directory?(f) } @@ -87,6 +86,8 @@ class Puppet::Module end # Split the path into the module and the rest of the path. + # This method can and often does return nil, so anyone calling + # it needs to handle that. def self.split_path(path) if path =~ %r/^#{File::SEPARATOR}/ return nil diff --git a/spec/unit/other/modules.rb b/spec/unit/other/modules.rb index f53c43e89..26ca3907d 100755 --- a/spec/unit/other/modules.rb +++ b/spec/unit/other/modules.rb @@ -108,22 +108,55 @@ describe Puppet::Module, " when searching for templates" do after { Puppet.settings.clear } end -describe Puppet::Module, " when searching for manifests" do - it "should return the manifests from the first found module" do - Puppet[:modulepath] = "/one:/two" - File.stubs(:directory?).returns(true) - Dir.expects(:glob).with("/one/mymod/manifests/init.pp").returns(%w{/one/mymod/manifests/init.pp}) - Puppet::Module.find_manifests("mymod/init.pp").should == ["/one/mymod/manifests/init.pp"] +describe Puppet::Module, " when searching for manifests when no module is found" do + before do + File.stubs(:find).returns(nil) end - it "should search the cwd if no module is found" do - Puppet[:modulepath] = "/one:/two" - File.stubs(:find).returns(nil) + it "should not look for modules when paths are fully qualified" do + Puppet.expects(:value).with(:modulepath).never + file = "/fully/qualified/file.pp" + Dir.stubs(:glob).with(file).returns([file]) + Puppet::Module.find_manifests(file) + end + + it "should directly return fully qualified files" do + file = "/fully/qualified/file.pp" + Dir.stubs(:glob).with(file).returns([file]) + Puppet::Module.find_manifests(file).should == [file] + end + + it "should match against provided fully qualified patterns" do + pattern = "/fully/qualified/pattern/*" + Dir.expects(:glob).with(pattern).returns(%w{my file list}) + Puppet::Module.find_manifests(pattern).should == %w{my file list} + end + + it "should look for files relative to the current directory" do cwd = Dir.getwd Dir.expects(:glob).with("#{cwd}/mymod/init.pp").returns(["#{cwd}/mymod/init.pp"]) Puppet::Module.find_manifests("mymod/init.pp").should == ["#{cwd}/mymod/init.pp"] end + it "should only return files, not directories" do + pattern = "/fully/qualified/pattern/*" + file = "/my/file" + dir = "/my/directory" + Dir.expects(:glob).with(pattern).returns([file, dir]) + FileTest.expects(:directory?).with(file).returns(false) + FileTest.expects(:directory?).with(dir).returns(true) + Puppet::Module.find_manifests(pattern).should == [file] + end +end + +describe Puppet::Module, " when searching for manifests in a found module" do + it "should return the manifests from the first found module" do + Puppet[:modulepath] = "/one:/two" + File.stubs(:directory?).returns(true) + Dir.expects(:glob).with("/one/mymod/manifests/init.pp").returns(%w{/one/mymod/manifests/init.pp}) + Puppet::Module.find_manifests("mymod/init.pp").should == ["/one/mymod/manifests/init.pp"] + end + it "should use the node environment if specified" do Puppet.settings.expects(:value).with(:modulepath, "myenv").returns("/env/modules") File.stubs(:directory?).returns(true) |