diff options
author | Luke Kanies <luke@madstop.com> | 2008-04-08 02:38:20 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-04-08 11:33:50 -0500 |
commit | 69a321f07dc0cbec7a0471a3378e9330d12c47b7 (patch) | |
tree | 64167cfbda61b43e5802dab97d2f832309a48216 /spec | |
parent | f9881edd5d4b9f86c1da1c66fb12324d0f9c3c41 (diff) | |
download | puppet-69a321f07dc0cbec7a0471a3378e9330d12c47b7.tar.gz puppet-69a321f07dc0cbec7a0471a3378e9330d12c47b7.tar.xz puppet-69a321f07dc0cbec7a0471a3378e9330d12c47b7.zip |
Fixing the tests that were failing because of the use
of the indirection request object.
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/unit/file_serving/indirection_hooks.rb | 204 |
1 files changed, 109 insertions, 95 deletions
diff --git a/spec/unit/file_serving/indirection_hooks.rb b/spec/unit/file_serving/indirection_hooks.rb index 34614b7b8..160e3ff0a 100755 --- a/spec/unit/file_serving/indirection_hooks.rb +++ b/spec/unit/file_serving/indirection_hooks.rb @@ -7,104 +7,118 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/file_serving/indirection_hooks' -describe Puppet::FileServing::IndirectionHooks, " when being used to select termini" do +describe Puppet::FileServing::IndirectionHooks do before do @object = Object.new @object.extend(Puppet::FileServing::IndirectionHooks) - end - - it "should escape the key before parsing" do - uri = stub 'uri', :scheme => "puppet", :host => "blah", :path => "/something" - URI.expects(:escape).with("mykey").returns("http://myhost/blah") - URI.expects(:parse).with("http://myhost/blah").returns(uri) - @object.select_terminus("mykey") - end - - it "should use the URI class to parse the key" do - uri = stub 'uri', :scheme => "puppet", :host => "blah", :path => "/something" - URI.expects(:parse).with("http://myhost/blah").returns(uri) - @object.select_terminus("http://myhost/blah") - end - - it "should choose :rest when the protocol is 'puppet'" do - @object.select_terminus("puppet://host/module/file").should == :rest - end - - it "should choose :file_server when the protocol is 'puppetmounts' and the mount name is not 'modules'" do - modules = mock 'modules' - @object.stubs(:terminus).with(:modules).returns(modules) - modules.stubs(:find_module).returns(nil) - - @object.select_terminus("puppetmounts://host/notmodules/file").should == :file_server - end - - it "should choose :file_server when no server name is provided, the process name is 'puppet', and the mount name is not 'modules'" do - modules = mock 'modules' - @object.stubs(:terminus).with(:modules).returns(modules) - modules.stubs(:find_module).returns(nil) - - Puppet.settings.expects(:value).with(:name).returns("puppet") - @object.select_terminus("puppet:///notmodules/file").should == :file_server - end - - it "should choose :modules if it would normally choose :file_server but the mount name is 'modules'" do - @object.select_terminus("puppetmounts://host/modules/mymod/file").should == :modules - end - - it "should choose :modules it would normally choose :file_server but a module exists with the mount name" do - modules = mock 'modules' - - @object.expects(:terminus).with(:modules).returns(modules) - modules.expects(:find_module).with("mymod", nil).returns(:thing) - - @object.select_terminus("puppetmounts://host/mymod/file").should == :modules - end - - it "should choose :rest when no server name is provided and the process name is not 'puppet'" do - Puppet.settings.expects(:value).with(:name).returns("puppetd") - @object.select_terminus("puppet:///module/file").should == :rest - end - - it "should choose :file when the protocol is 'file'" do - @object.select_terminus("file://host/module/file").should == :file - end - - it "should choose :file when the URI is a normal path name" do - @object.select_terminus("/module/file").should == :file - end - - # This is so that we only choose modules over mounts, not file - it "should choose :file when the protocol is 'file' and the fully qualified path starts with '/modules'" do - @object.select_terminus("file://host/modules/file").should == :file - end - - it "should fail when a protocol other than :puppet, :file, or :puppetmounts is used" do - proc { @object.select_terminus("http:///module/file") }.should raise_error(ArgumentError) - end -end - -describe Puppet::FileServing::IndirectionHooks, " when looking for a module whose name matches the mount name" do - before do - @object = Object.new - @object.extend(Puppet::FileServing::IndirectionHooks) - - @modules = mock 'modules' - @object.stubs(:terminus).with(:modules).returns(@modules) - end - - it "should use the modules terminus to look up the module" do - @modules.expects(:find_module).with("mymod", nil) - @object.select_terminus("puppetmounts://host/mymod/my/file") - end - - it "should pass the node name to the modules terminus" do - @modules.expects(:find_module).with("mymod", nil) - @object.select_terminus("puppetmounts://host/mymod/my/file") - end - it "should log a deprecation warning if a module is found" do - @modules.expects(:find_module).with("mymod", nil).returns(:something) - Puppet.expects(:warning) - @object.select_terminus("puppetmounts://host/mymod/my/file") + @request = stub 'request', :key => "http://myhost/blah", :options => {:node => "whatever"} + end + + describe "when being used to select termini" do + it "should escape the key before parsing" do + uri = stub 'uri', :scheme => "puppet", :host => "blah", :path => "/something" + URI.expects(:escape).with("http://myhost/blah").returns("escaped_blah") + URI.expects(:parse).with("escaped_blah").returns(uri) + @object.select_terminus(@request) + end + + it "should use the URI class to parse the key" do + uri = stub 'uri', :scheme => "puppet", :host => "blah", :path => "/something" + URI.expects(:parse).with("http://myhost/blah").returns(uri) + @object.select_terminus @request + end + + it "should choose :rest when the protocol is 'puppet'" do + @request.stubs(:key).returns "puppet://host/module/file" + @object.select_terminus(@request).should == :rest + end + + it "should choose :file_server when the protocol is 'puppetmounts' and the mount name is not 'modules'" do + modules = mock 'modules' + @object.stubs(:terminus).with(:modules).returns(modules) + modules.stubs(:find_module).returns(nil) + + @request.stubs(:key).returns "puppetmounts://host/notmodules/file" + + @object.select_terminus(@request).should == :file_server + end + + it "should choose :file_server when no server name is provided, the process name is 'puppet', and the mount name is not 'modules'" do + modules = mock 'modules' + @object.stubs(:terminus).with(:modules).returns(modules) + modules.stubs(:find_module).returns(nil) + + Puppet.settings.expects(:value).with(:name).returns("puppet") + @request.stubs(:key).returns "puppet:///notmodules/file" + @object.select_terminus(@request).should == :file_server + end + + it "should choose :modules if it would normally choose :file_server but the mount name is 'modules'" do + @request.stubs(:key).returns "puppetmounts://host/modules/mymod/file" + @object.select_terminus(@request).should == :modules + end + + it "should choose :modules if it would normally choose :file_server but a module exists with the mount name" do + modules = mock 'modules' + + @object.expects(:terminus).with(:modules).returns(modules) + modules.expects(:find_module).with("mymod", @request.options[:node]).returns(:thing) + + @request.stubs(:key).returns "puppetmounts://host/mymod/file" + @object.select_terminus(@request).should == :modules + end + + it "should choose :rest when no server name is provided and the process name is not 'puppet'" do + Puppet.settings.expects(:value).with(:name).returns("puppetd") + @request.stubs(:key).returns "puppet:///module/file" + @object.select_terminus(@request).should == :rest + end + + it "should choose :file when the protocol is 'file'" do + @request.stubs(:key).returns "file://host/module/file" + @object.select_terminus(@request).should == :file + end + + it "should choose :file when the URI is a normal path name" do + @request.stubs(:key).returns "/module/file" + @object.select_terminus(@request).should == :file + end + + # This is so that we only choose modules over mounts, not file + it "should choose :file when the protocol is 'file' and the fully qualified path starts with '/modules'" do + @request.stubs(:key).returns "/module/file" + @object.select_terminus(@request).should == :file + end + + it "should fail when a protocol other than :puppet, :file, or :puppetmounts is used" do + @request.stubs(:key).returns "http:///module/file" + proc { @object.select_terminus(@request) }.should raise_error(ArgumentError) + end + end + + describe "when looking for a module whose name matches the mount name" do + before do + @modules = mock 'modules' + @object.stubs(:terminus).with(:modules).returns(@modules) + + @request.stubs(:key).returns "puppetmounts://host/mymod/file" + end + + it "should use the modules terminus to look up the module" do + @modules.expects(:find_module).with("mymod", @request.options[:node]) + @object.select_terminus @request + end + + it "should pass the node name to the modules terminus" do + @modules.expects(:find_module).with("mymod", @request.options[:node]) + @object.select_terminus @request + end + + it "should log a deprecation warning if a module is found" do + @modules.expects(:find_module).with("mymod", @request.options[:node]).returns(:something) + Puppet.expects(:warning) + @object.select_terminus @request + end end end |