diff options
Diffstat (limited to 'spec/unit/indirector/module_files.rb')
-rwxr-xr-x | spec/unit/indirector/module_files.rb | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/spec/unit/indirector/module_files.rb b/spec/unit/indirector/module_files.rb index 32dedd4f1..20c9f499a 100755 --- a/spec/unit/indirector/module_files.rb +++ b/spec/unit/indirector/module_files.rb @@ -25,49 +25,47 @@ describe Puppet::Indirector::ModuleFiles do @module_files = @module_files_class.new - @uri = "puppetmounts://host/modules/my/local/file" @module = Puppet::Module.new("mymod", "/module/path") - @request = stub 'request', :key => @uri, :options => {}, :node => nil, :ip => nil, :method => :find + @request = Puppet::Indirector::Request.new(:mytype, :find, "puppet://host/modules/mymod/local/file") end describe Puppet::Indirector::ModuleFiles, " when finding files" do + before do + Puppet::Module.stubs(:find).returns @module + end - it "should strip off the leading '/modules' mount name" do - Puppet::Module.expects(:find).with('my', "myenv").returns @module + it "should strip off the leading 'modules/' mount name" do + Puppet::Module.expects(:find).with { |key, env| key == 'mymod' }.returns @module @module_files.find(@request) end - it "should not strip off leading terms that start with '/modules' but are longer words" do - @request.stubs(:key).returns "puppetmounts://host/modulestart/my/local/file" - Puppet::Module.expects(:find).with('modulestart', "myenv").returns nil + it "should not strip off leading terms that start with 'modules' but are longer words" do + @request.stubs(:key).returns "modulestart/mymod/local/file" + Puppet::Module.expects(:find).with { |key, env| key == 'modulestart'}.returns nil @module_files.find(@request) end it "should search for a module whose name is the first term in the remaining file path" do - Puppet::Module.expects(:find).with('my', "myenv").returns @module @module_files.find(@request) end it "should search for a file relative to the module's files directory" do - Puppet::Module.expects(:find).with('my', "myenv").returns @module FileTest.expects(:exists?).with("/module/path/files/local/file") @module_files.find(@request) end it "should return nil if the module does not exist" do - Puppet::Module.expects(:find).with('my', "myenv").returns nil + Puppet::Module.expects(:find).returns nil @module_files.find(@request).should be_nil end it "should return nil if the module exists but the file does not" do - Puppet::Module.expects(:find).with('my', "myenv").returns @module FileTest.expects(:exists?).with("/module/path/files/local/file").returns(false) @module_files.find(@request).should be_nil end it "should return an instance of the model if a module is found and the file exists" do - Puppet::Module.expects(:find).with('my', "myenv").returns @module FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true) @model.expects(:new).returns(:myinstance) @module_files.find(@request).should == :myinstance @@ -76,7 +74,7 @@ describe Puppet::Indirector::ModuleFiles do it "should use the node's environment to look up the module if the node name is provided" do node = stub "node", :environment => "testing" Puppet::Node.expects(:find).with("mynode").returns(node) - Puppet::Module.expects(:find).with('my', "testing") + Puppet::Module.expects(:find).with('mymod', "testing") @request.stubs(:node).returns "mynode" @module_files.find(@request) @@ -85,7 +83,7 @@ describe Puppet::Indirector::ModuleFiles do it "should use the default environment setting to look up the module if the node name is not provided" do env = stub "environment", :name => "testing" Puppet::Node::Environment.stubs(:new).returns(env) - Puppet::Module.expects(:find).with('my', "testing") + Puppet::Module.expects(:find).with('mymod', "testing") @module_files.find(@request) end end @@ -93,13 +91,13 @@ describe Puppet::Indirector::ModuleFiles do describe Puppet::Indirector::ModuleFiles, " when returning instances" do before do - Puppet::Module.expects(:find).with('my', "myenv").returns @module + Puppet::Module.expects(:find).with('mymod', "myenv").returns @module FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true) @instance = mock 'instance' end it "should create the instance with the key used to find the instance" do - @model.expects(:new).with { |key, *options| key == @uri } + @model.expects(:new).with { |key, *options| key == @request.key } @module_files.find(@request) end @@ -149,19 +147,19 @@ describe Puppet::Indirector::ModuleFiles do end it "should use the path directly from the URI if it already includes /modules" do - @request.expects(:key).returns "puppetmounts://host/modules/my/file" - @configuration.expects(:authorized?).with { |uri, *args| uri == "/modules/my/file" } + @request.expects(:key).returns "modules/my/file" + @configuration.expects(:authorized?).with { |uri, *args| uri == "modules/my/file" } @module_files.authorized?(@request) end - it "should add /modules to the file path if it's not included in the URI" do - @request.expects(:key).returns "puppetmounts://host/my/file" - @configuration.expects(:authorized?).with { |uri, *args| uri == "/modules/my/file" } + it "should add modules/ to the file path if it's not included in the URI" do + @request.expects(:key).returns "my/file" + @configuration.expects(:authorized?).with { |uri, *args| uri == "modules/my/file" } @module_files.authorized?(@request) end it "should pass the node name to the file server configuration" do - @request.expects(:key).returns "puppetmounts://host/my/file" + @request.expects(:key).returns "my/file" @configuration.expects(:authorized?).with { |key, options| options[:node] == "mynode" } @request.stubs(:node).returns "mynode" @module_files.authorized?(@request) @@ -186,41 +184,41 @@ describe Puppet::Indirector::ModuleFiles do describe Puppet::Indirector::ModuleFiles, " when searching for files" do - it "should strip off the leading '/modules' mount name" do + it "should strip off the leading 'modules/' mount name" do Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv")) - Puppet::Module.expects(:find).with('my', "myenv").returns @module + Puppet::Module.expects(:find).with { |key, env| key == 'mymod'}.returns @module @module_files.search(@request) end it "should not strip off leading terms that start with '/modules' but are longer words" do Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv")) Puppet::Module.expects(:find).with('modulestart', "myenv").returns nil - @request.stubs(:key).returns "puppetmounts://host/modulestart/my/local/file" + @request.stubs(:key).returns "modulestart/my/local/file" @module_files.search @request end it "should search for a module whose name is the first term in the remaining file path" do Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv")) - Puppet::Module.expects(:find).with('my', "myenv").returns @module + Puppet::Module.expects(:find).with('mymod', "myenv").returns @module @module_files.search(@request) end it "should search for a file relative to the module's files directory" do Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv")) - Puppet::Module.expects(:find).with('my', "myenv").returns @module + Puppet::Module.expects(:find).with('mymod', "myenv").returns @module FileTest.expects(:exists?).with("/module/path/files/local/file") @module_files.search(@request) end it "should return nil if the module does not exist" do Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv")) - Puppet::Module.expects(:find).with('my', "myenv").returns nil + Puppet::Module.expects(:find).with('mymod', "myenv").returns nil @module_files.search(@request).should be_nil end it "should return nil if the module exists but the file does not" do Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv")) - Puppet::Module.expects(:find).with('my', "myenv").returns @module + Puppet::Module.expects(:find).with('mymod', "myenv").returns @module FileTest.expects(:exists?).with("/module/path/files/local/file").returns(false) @module_files.search(@request).should be_nil end @@ -228,7 +226,7 @@ describe Puppet::Indirector::ModuleFiles do it "should use the node's environment to look up the module if the node name is provided" do node = stub "node", :environment => "testing" Puppet::Node.expects(:find).with("mynode").returns(node) - Puppet::Module.expects(:find).with('my', "testing") + Puppet::Module.expects(:find).with('mymod', "testing") @request.stubs(:node).returns "mynode" @module_files.search(@request) end @@ -236,13 +234,13 @@ describe Puppet::Indirector::ModuleFiles do it "should use the default environment setting to look up the module if the node name is not provided and the environment is not set to ''" do env = stub 'env', :name => "testing" Puppet::Node::Environment.stubs(:new).returns(env) - Puppet::Module.expects(:find).with('my', "testing") + Puppet::Module.expects(:find).with('mymod', "testing") @module_files.search(@request) end it "should use :path2instances from the terminus_helper to return instances if a module is found and the file exists" do Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv")) - Puppet::Module.expects(:find).with('my', "myenv").returns @module + Puppet::Module.expects(:find).with('mymod', "myenv").returns @module FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true) @module_files.expects(:path2instances).with(@request, "/module/path/files/local/file") @module_files.search(@request) @@ -250,7 +248,7 @@ describe Puppet::Indirector::ModuleFiles do it "should pass the request directly to :path2instances" do Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv")) - Puppet::Module.expects(:find).with('my', "myenv").returns @module + Puppet::Module.expects(:find).with('mymod', "myenv").returns @module FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true) @module_files.expects(:path2instances).with(@request, "/module/path/files/local/file") @module_files.search(@request) |