diff options
| author | Rick Bradley <rick@rickbradley.com> | 2008-03-31 11:59:16 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-04-11 13:10:35 -0500 |
| commit | 7a7343458402e493f690633f3cfa78abef316d28 (patch) | |
| tree | 9ed3ef94f2816c34a95b6c16193ab8bfafe71fc5 /spec/unit/network/http/webrick.rb | |
| parent | a1c45790f6cac265a7bac7d63bfb8a3204ed228f (diff) | |
| download | puppet-7a7343458402e493f690633f3cfa78abef316d28.tar.gz puppet-7a7343458402e493f690633f3cfa78abef316d28.tar.xz puppet-7a7343458402e493f690633f3cfa78abef316d28.zip | |
Much larger commit than I would like to land at once. This is all REST-related code. Two specs are failing related to how Mongrel is initialized for REST; will fix those shortly.
REST indirector now supports find, with deserialization. Network code in indirector now. Will still need to un-hardwire address/port for outbound connections. Will still need to urlencode path parameters.
Code for search, destroy, update is coming, should be similar to find.
Reworked how the Handler module is used. Needed to be included, rather than inherited. Needed to sidestep initializers for actual web servers (webrick, mongrel), needed to be possible to have handler-including class be used as a class (aka servlet) instead of as an instance.
Webrick handler registration is now abstracted to "above" the servlet.
Provided a #model method to use instead of @model in handler module. This allows neutering during testing.
Brought class_for_protocol up into http/webrick class as a (tested) class method.
Integration tests for rest indirection. Split server integration tests into mongrel and webrick tests.
Got Node/REST working properly wrt the crazy-ass autoloader thing.
We're now actually passing traffic w/ webrick, fwiw.
Diffstat (limited to 'spec/unit/network/http/webrick.rb')
| -rw-r--r-- | spec/unit/network/http/webrick.rb | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/spec/unit/network/http/webrick.rb b/spec/unit/network/http/webrick.rb index 6a4c50142..05ed2f0e2 100644 --- a/spec/unit/network/http/webrick.rb +++ b/spec/unit/network/http/webrick.rb @@ -14,7 +14,7 @@ end describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do before do - @mock_webrick = mock('webrick') + @mock_webrick = stub('webrick', :[] => {}) [:mount, :start, :shutdown].each {|meth| @mock_webrick.stubs(meth)} WEBrick::HTTPServer.stubs(:new).returns(@mock_webrick) @server = Puppet::Network::HTTP::WEBrick.new @@ -64,28 +64,44 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do mock_handler = mock("handler instance for [#{protocol}]") mock_handler_class = mock("handler class for [#{protocol}]") @listen_params[:handlers].each do |handler| - mock_handler_class.expects(:new).with {|args| - args[:server] == @mock_webrick and args[:handler] == handler - }.returns(mock_handler) + @mock_webrick.expects(:mount) end - @server.expects(:class_for_protocol).with(protocol).at_least_once.returns(mock_handler_class) end @server.listen(@listen_params) end it "should use a WEBrick + REST class to configure WEBrick when REST services are requested" do - Puppet::Network::HTTP::WEBrickREST.expects(:new).at_least_once + Puppet::Network::HTTP::WEBrick.expects(:class_for_protocol).with(:rest).at_least_once @server.listen(@listen_params.merge(:protocols => [:rest])) end it "should fail if services from an unknown protocol are requested" do - Proc.new { @server.listen(@listen_params.merge(:protocols => [ :foo ]))}.should raise_error(ArgumentError) + Proc.new { @server.listen(@listen_params.merge(:protocols => [ :foo ]))}.should raise_error end end + +describe Puppet::Network::HTTP::WEBrick, "when looking up the class to handle a protocol" do + it "should require a protocol" do + lambda { Puppet::Network::HTTP::WEBrick.class_for_protocol }.should raise_error(ArgumentError) + end + + it "should accept a protocol" do + lambda { Puppet::Network::HTTP::WEBrick.class_for_protocol("bob") }.should_not raise_error(ArgumentError) + end + + it "should use a WEBrick + REST class when a REST protocol is specified" do + Puppet::Network::HTTP::WEBrick.class_for_protocol("rest").should == Puppet::Network::HTTP::WEBrickREST + end + + it "should fail when an unknown protocol is specified" do + lambda { Puppet::Network::HTTP::WEBrick.class_for_protocol("abcdefg") }.should raise_error + end +end + describe Puppet::Network::HTTP::WEBrick, "when turning off listening" do before do - @mock_webrick = mock('webrick') + @mock_webrick = stub('webrick', :[] => {}) [:mount, :start, :shutdown].each {|meth| @mock_webrick.stubs(meth)} WEBrick::HTTPServer.stubs(:new).returns(@mock_webrick) @server = Puppet::Network::HTTP::WEBrick.new |
