summaryrefslogtreecommitdiffstats
path: root/spec/unit/network/http
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2007-10-15 14:47:25 -0500
committerRick Bradley <rick@rickbradley.com>2007-10-15 14:47:25 -0500
commitc34efbccf1eec9957253d4fcdcb4ea9c79837ad8 (patch)
treeae04acf64b2b2a772c9d7d113fccf994fc6c71a3 /spec/unit/network/http
parent9a179ec3a9df62c6179e7151831c4f07197cfbce (diff)
downloadpuppet-c34efbccf1eec9957253d4fcdcb4ea9c79837ad8.tar.gz
puppet-c34efbccf1eec9957253d4fcdcb4ea9c79837ad8.tar.xz
puppet-c34efbccf1eec9957253d4fcdcb4ea9c79837ad8.zip
Hooking up address/port support for the various servers w/ specs. Still need to start up a webrick server w/ address + port (this is far too incestuous with Puppet lib & Puppet.start at the moment).
Diffstat (limited to 'spec/unit/network/http')
-rw-r--r--spec/unit/network/http/mongrel.rb43
-rw-r--r--spec/unit/network/http/webrick.rb29
2 files changed, 48 insertions, 24 deletions
diff --git a/spec/unit/network/http/mongrel.rb b/spec/unit/network/http/mongrel.rb
index 3456a16d6..f964e6844 100644
--- a/spec/unit/network/http/mongrel.rb
+++ b/spec/unit/network/http/mongrel.rb
@@ -15,45 +15,59 @@ end
describe Puppet::Network::HTTP::Mongrel, "when turning on listening" do
before do
@server = Puppet::Network::HTTP::Mongrel.new
+ @mock_mongrel = mock('mongrel')
+ @mock_mongrel.stubs(:run)
+ Mongrel::HttpServer.stubs(:new).returns(@mock_mongrel)
+ @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => { :foo => :bar }}
end
it "should fail if already listening" do
- @server.listen(:foo => :bar)
- Proc.new { @server.listen(:foo => :bar) }.should raise_error(RuntimeError)
+ @server.listen(@listen_params)
+ Proc.new { @server.listen(@listen_params) }.should raise_error(RuntimeError)
end
it "should require at least one handler" do
- Proc.new { @server.listen }.should raise_error(ArgumentError)
+ Proc.new { @server.listen(@listen_params.delete_if {|k,v| :handlers == k}) }.should raise_error(ArgumentError)
+ end
+
+ it "should require a listening address to be specified" do
+ Proc.new { @server.listen(@listen_params.delete_if {|k,v| :address == k})}.should raise_error(ArgumentError)
+ end
+
+ it "should require a listening port to be specified" do
+ Proc.new { @server.listen(@listen_params.delete_if {|k,v| :port == k})}.should raise_error(ArgumentError)
end
it "should order a mongrel server to start" do
- mock_mongrel = mock('mongrel httpserver')
- mock_mongrel.expects(:run)
- Mongrel::HttpServer.expects(:new).returns(mock_mongrel)
- @server.listen(:foo => :bar)
+ @mock_mongrel.expects(:run)
+ @server.listen(@listen_params)
+ end
+
+ it "should tell mongrel to listen on the specified address and port" do
+ Mongrel::HttpServer.expects(:new).with("127.0.0.1", 31337).returns(@mock_mongrel)
+ @server.listen(@listen_params)
end
it "should be listening" do
mock_mongrel = mock('mongrel httpserver')
mock_mongrel.expects(:run)
Mongrel::HttpServer.expects(:new).returns(mock_mongrel)
- @server.listen(:foo => :bar)
+ @server.listen(@listen_params)
@server.should be_listening
end
it "should instantiate a specific handler (mongrel+rest, e.g.) for each handler, for each protocol being served (xmlrpc, rest, etc.)"
it "should mount handlers on a mongrel path"
- it "should be able to specify the address on which mongrel will listen"
- it "should be able to specify the port on which mongrel will listen"
end
-describe Puppet::Network::HTTP::WEBrick, "when turning off listening" do
+describe Puppet::Network::HTTP::Mongrel, "when turning off listening" do
before do
@mock_mongrel = mock('mongrel httpserver')
@mock_mongrel.stubs(:run)
- @mock_mongrel.stubs(:graceful_shutdown)
Mongrel::HttpServer.stubs(:new).returns(@mock_mongrel)
+
@server = Puppet::Network::HTTP::Mongrel.new
+ @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => { :foo => :bar }}
end
it "should fail unless listening" do
@@ -61,13 +75,14 @@ describe Puppet::Network::HTTP::WEBrick, "when turning off listening" do
end
it "should order mongrel server to stop" do
- @server.listen(:foo => :bar)
+ @server.listen(@listen_params)
@mock_mongrel.expects(:graceful_shutdown)
@server.unlisten
end
it "should not be listening" do
- @server.listen(:foo => :bar)
+ @server.listen(@listen_params)
+ @mock_mongrel.stubs(:graceful_shutdown)
@server.unlisten
@server.should_not be_listening
end
diff --git a/spec/unit/network/http/webrick.rb b/spec/unit/network/http/webrick.rb
index b070ec0d6..9ab97e831 100644
--- a/spec/unit/network/http/webrick.rb
+++ b/spec/unit/network/http/webrick.rb
@@ -15,39 +15,48 @@ end
describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
before do
@server = Puppet::Network::HTTP::WEBrick.new
+ @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => { :foo => :bar }}
Puppet.stubs(:start)
end
it "should fail if already listening" do
- @server.listen(:foo => :bar)
- Proc.new { @server.listen(:foo => :bar) }.should raise_error(RuntimeError)
+ @server.listen(@listen_params)
+ Proc.new { @server.listen(@listen_params) }.should raise_error(RuntimeError)
end
it "should require at least one handler" do
- Proc.new { @server.listen }.should raise_error(ArgumentError)
+ Proc.new { @server.listen(@listen_params.delete_if {|k,v| :handlers == k}) }.should raise_error(ArgumentError)
end
+ it "should require a listening address to be specified" do
+ Proc.new { @server.listen(@listen_params.delete_if {|k,v| :address == k})}.should raise_error(ArgumentError)
+ end
+
+ it "should require a listening port to be specified" do
+ Proc.new { @server.listen(@listen_params.delete_if {|k,v| :port == k})}.should raise_error(ArgumentError)
+ end
+
it "should order a webrick server to start" do
Puppet.expects(:start)
- @server.listen(:foo => :bar)
+ @server.listen(@listen_params)
end
+ it "should tell webrick to listen on the specified address and port"
+
it "should be listening" do
- @server.listen(:foo => :bar)
+ @server.listen(@listen_params)
@server.should be_listening
end
it "should instantiate a specific handler (webrick+rest, e.g.) for each handler, for each protocol being served (xmlrpc, rest, etc.)"
it "should mount handlers on a webrick path"
-
- it "should be able to specify the address on which webrick will listen"
- it "should be able to specify the port on which webrick will listen"
end
describe Puppet::Network::HTTP::WEBrick, "when turning off listening" do
before do
@server = Puppet::Network::HTTP::WEBrick.new
@server.stubs(:shutdown)
+ @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => { :foo => :bar }}
Puppet.stubs(:start).returns(true)
end
@@ -58,12 +67,12 @@ describe Puppet::Network::HTTP::WEBrick, "when turning off listening" do
it "should order webrick server to stop" do
@server.should respond_to(:shutdown)
@server.expects(:shutdown)
- @server.listen(:foo => :bar)
+ @server.listen(@listen_params)
@server.unlisten
end
it "should no longer be listening" do
- @server.listen(:foo => :bar)
+ @server.listen(@listen_params)
@server.unlisten
@server.should_not be_listening
end