diff --git a/lib/puppet/file_serving/mount/modules.rb b/lib/puppet/file_serving/mount/modules.rb index 86b5e1cdd..3cbacb276 100644 --- a/lib/puppet/file_serving/mount/modules.rb +++ b/lib/puppet/file_serving/mount/modules.rb @@ -1,25 +1,24 @@ require 'puppet/file_serving/mount' # This is the modules-specific mount: it knows how to search through # modules for files. Yay. class Puppet::FileServing::Mount::Modules < Puppet::FileServing::Mount # Return an instance of the appropriate class. def find(path, request) + raise "No module specified" if path.to_s.empty? module_name, relative_path = path.split("/", 2) return nil unless mod = request.environment.module(module_name) mod.file(relative_path) end def search(path, request) - module_name, relative_path = path.split("/", 2) - return nil unless mod = request.environment.module(module_name) - - return nil unless path = mod.file(relative_path) - [path] + if result = find(path, request) + [result] + end end def valid? true end end diff --git a/spec/unit/file_serving/mount/modules_spec.rb b/spec/unit/file_serving/mount/modules_spec.rb index 2d582daa2..306f3070d 100755 --- a/spec/unit/file_serving/mount/modules_spec.rb +++ b/spec/unit/file_serving/mount/modules_spec.rb @@ -1,62 +1,70 @@ #!/usr/bin/env rspec require 'spec_helper' require 'puppet/file_serving/mount/modules' describe Puppet::FileServing::Mount::Modules do before do @mount = Puppet::FileServing::Mount::Modules.new("modules") @environment = stub 'environment', :module => nil @request = stub 'request', :environment => @environment end describe "when finding files" do + it "should fail if no module is specified" do + expect { @mount.find("", @request) }.to raise_error(/No module specified/) + end + it "should use the provided environment to find the module" do @environment.expects(:module) @mount.find("foo", @request) end it "should treat the first field of the relative path as the module name" do @environment.expects(:module).with("foo") @mount.find("foo/bar/baz", @request) end it "should return nil if the specified module does not exist" do @environment.expects(:module).with("foo").returns nil @mount.find("foo/bar/baz", @request) end it "should return the file path from the module" do mod = mock 'module' mod.expects(:file).with("bar/baz").returns "eh" @environment.expects(:module).with("foo").returns mod @mount.find("foo/bar/baz", @request).should == "eh" end end describe "when searching for files" do + it "should fail if no module is specified" do + expect { @mount.find("", @request) }.to raise_error(/No module specified/) + end + it "should use the node's environment to search the module" do @environment.expects(:module) @mount.search("foo", @request) end it "should treat the first field of the relative path as the module name" do @environment.expects(:module).with("foo") @mount.search("foo/bar/baz", @request) end it "should return nil if the specified module does not exist" do @environment.expects(:module).with("foo").returns nil @mount.search("foo/bar/baz", @request) end it "should return the file path as an array from the module" do mod = mock 'module' mod.expects(:file).with("bar/baz").returns "eh" @environment.expects(:module).with("foo").returns mod @mount.search("foo/bar/baz", @request).should == ["eh"] end end end