summaryrefslogtreecommitdiffstats
path: root/spec/unit/network
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-07-29 00:46:11 -0500
committerLuke Kanies <luke@madstop.com>2008-07-29 00:46:11 -0500
commit40375a8fc34dbd85d87f507ba72c7394b25b7271 (patch)
treeefd5a93980b042b73322bd31e6fdb41203d07576 /spec/unit/network
parent93eeff59d807261ed154cc104e318ae604602430 (diff)
parent8f5800f0608dff46407cb5f23ee73f314fe051e8 (diff)
downloadpuppet-40375a8fc34dbd85d87f507ba72c7394b25b7271.tar.gz
puppet-40375a8fc34dbd85d87f507ba72c7394b25b7271.tar.xz
puppet-40375a8fc34dbd85d87f507ba72c7394b25b7271.zip
Merge branch '0.24.x' into merging
Conflicts: test/ral/type/filesources.rb
Diffstat (limited to 'spec/unit/network')
-rwxr-xr-xspec/unit/network/client/master.rb96
-rwxr-xr-xspec/unit/network/http.rb12
-rwxr-xr-xspec/unit/network/http/mongrel.rb10
-rwxr-xr-xspec/unit/network/http/mongrel/rest.rb16
-rwxr-xr-xspec/unit/network/http/webrick.rb1
-rwxr-xr-xspec/unit/network/http/webrick/rest.rb1
6 files changed, 109 insertions, 27 deletions
diff --git a/spec/unit/network/client/master.rb b/spec/unit/network/client/master.rb
index 79ab8c86f..754fd0583 100755
--- a/spec/unit/network/client/master.rb
+++ b/spec/unit/network/client/master.rb
@@ -59,34 +59,92 @@ describe Puppet::Network::Client::Master, " when retrieving the catalog" do
@client.getconfig
end
- it "should load the retrieved catalog using YAML" do
- @client.stubs(:dostorage)
- @client.class.stubs(:facts).returns(@facts)
- @master.stubs(:getconfig).returns("myconfig")
+ describe "when the catalog format is set to yaml" do
+ before do
+ Puppet.settings.stubs(:value).returns "foo"
+ Puppet.settings.stubs(:value).with(:pluginsync).returns false
+ Puppet.settings.stubs(:value).with(:configtimeout).returns 10
+ Puppet.settings.stubs(:value).with(:factsync).returns false
+ Puppet.settings.stubs(:value).with(:catalog_format).returns "yaml"
+ end
- config = mock 'config'
- YAML.expects(:load).with("myconfig").returns(config)
+ it "should request a yaml-encoded catalog" do
+ @client.stubs(:dostorage)
+ @client.class.stubs(:facts).returns(@facts)
+ @master.expects(:getconfig).with { |*args| args[1] == "yaml" }
- @client.stubs(:setclasses)
+ @client.getconfig
+ end
- config.stubs(:classes)
- config.stubs(:to_catalog).returns(config)
- config.stubs(:host_config=)
- config.stubs(:from_cache).returns(true)
+ it "should load the retrieved catalog using YAML" do
+ @client.stubs(:dostorage)
+ @client.class.stubs(:facts).returns(@facts)
+ @master.stubs(:getconfig).returns("myconfig")
- @client.getconfig
+ config = mock 'config'
+ YAML.expects(:load).with("myconfig").returns(config)
+
+ @client.stubs(:setclasses)
+
+ config.stubs(:classes)
+ config.stubs(:to_catalog).returns(config)
+ config.stubs(:host_config=)
+ config.stubs(:from_cache).returns(true)
+
+ @client.getconfig
+ end
+
+ it "should use the cached catalog if the retrieved catalog cannot be converted from YAML" do
+ @client.stubs(:dostorage)
+ @client.class.stubs(:facts).returns(@facts)
+ @master.stubs(:getconfig).returns("myconfig")
+
+ YAML.expects(:load).with("myconfig").raises(ArgumentError)
+
+ @client.expects(:use_cached_config).with(true)
+
+ @client.getconfig
+ end
end
- it "should use the cached catalog if the retrieved catalog cannot be converted from YAML" do
- @client.stubs(:dostorage)
- @client.class.stubs(:facts).returns(@facts)
- @master.stubs(:getconfig).returns("myconfig")
+ describe "from Marshal" do
+ before do
+ Puppet.settings.stubs(:value).returns "foo"
+ Puppet.settings.stubs(:value).with(:pluginsync).returns false
+ Puppet.settings.stubs(:value).with(:configtimeout).returns 10
+ Puppet.settings.stubs(:value).with(:factsync).returns false
+ Puppet.settings.stubs(:value).with(:catalog_format).returns "marshal"
+ end
- YAML.expects(:load).with("myconfig").raises(ArgumentError)
+ it "should load the retrieved catalog using Marshal" do
+ @client.stubs(:dostorage)
+ @client.class.stubs(:facts).returns(@facts)
+ @master.stubs(:getconfig).returns("myconfig")
- @client.expects(:use_cached_config).with(true)
+ config = mock 'config'
+ Marshal.expects(:load).with("myconfig").returns(config)
- @client.getconfig
+ @client.stubs(:setclasses)
+
+ config.stubs(:classes)
+ config.stubs(:to_catalog).returns(config)
+ config.stubs(:host_config=)
+ config.stubs(:from_cache).returns(true)
+
+ @client.getconfig
+ end
+
+ it "should use the cached catalog if the retrieved catalog cannot be converted from Marshal" do
+ @client.stubs(:dostorage)
+ @client.class.stubs(:facts).returns(@facts)
+ @master.stubs(:getconfig).returns("myconfig")
+
+ Marshal.expects(:load).with("myconfig").raises(ArgumentError)
+
+ @client.expects(:use_cached_config).with(true)
+
+ @client.getconfig
+ end
end
it "should set the classes.txt file with the classes listed in the retrieved catalog" do
diff --git a/spec/unit/network/http.rb b/spec/unit/network/http.rb
index 79a0a88d4..1fa025b0b 100755
--- a/spec/unit/network/http.rb
+++ b/spec/unit/network/http.rb
@@ -12,9 +12,15 @@ describe Puppet::Network::HTTP do
Puppet::Network::HTTP.server_class_by_type(:webrick).should be(Puppet::Network::HTTP::WEBrick)
end
- if Puppet.features.mongrel?
- it "should return the mongrel HTTP server class when asked for a mongrel server" do
- Puppet::Network::HTTP.server_class_by_type(:mongrel).should be(Puppet::Network::HTTP::Mongrel)
+ describe "when asked for a mongrel server" do
+ if Puppet.features.mongrel?
+ it "should return the mongrel server class" do
+ Puppet::Network::HTTP.server_class_by_type(:mongrel).should be(Puppet::Network::HTTP::Mongrel)
+ end
+ else
+ it "should fail" do
+ lambda { Puppet::Network::HTTP.server_class_by_type(:mongrel) }.should raise_error(ArgumentError)
+ end
end
end
diff --git a/spec/unit/network/http/mongrel.rb b/spec/unit/network/http/mongrel.rb
index 1f87fd943..9c708067a 100755
--- a/spec/unit/network/http/mongrel.rb
+++ b/spec/unit/network/http/mongrel.rb
@@ -6,18 +6,22 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/network/http'
-describe Puppet::Network::HTTP::Mongrel, "after initializing" do
+describe "Puppet::Network::HTTP::Mongrel", "after initializing" do
confine "Mongrel is not available" => Puppet.features.mongrel?
it "should not be listening" do
+ require 'puppet/network/http/mongrel'
+
Puppet::Network::HTTP::Mongrel.new.should_not be_listening
end
end
-describe Puppet::Network::HTTP::Mongrel, "when turning on listening" do
+describe "Puppet::Network::HTTP::Mongrel", "when turning on listening" do
confine "Mongrel is not available" => Puppet.features.mongrel?
before do
+ require 'puppet/network/http/mongrel'
+
@server = Puppet::Network::HTTP::Mongrel.new
@mock_mongrel = mock('mongrel')
@mock_mongrel.stubs(:run)
@@ -109,7 +113,7 @@ describe Puppet::Network::HTTP::Mongrel, "when turning on listening" do
end
end
-describe Puppet::Network::HTTP::Mongrel, "when turning off listening" do
+describe "Puppet::Network::HTTP::Mongrel", "when turning off listening" do
confine "Mongrel is not available" => Puppet.features.mongrel?
before do
diff --git a/spec/unit/network/http/mongrel/rest.rb b/spec/unit/network/http/mongrel/rest.rb
index 3df925133..de5254a7a 100755
--- a/spec/unit/network/http/mongrel/rest.rb
+++ b/spec/unit/network/http/mongrel/rest.rb
@@ -3,10 +3,12 @@
require File.dirname(__FILE__) + '/../../../../spec_helper'
require 'puppet/network/http'
-describe Puppet::Network::HTTP::MongrelREST, "when initializing" do
+describe "Puppet::Network::HTTP::MongrelREST", "when initializing" do
confine "Mongrel is not available" => Puppet.features.mongrel?
before do
+ require 'puppet/network/http/mongrel/rest'
+
@mock_mongrel = mock('Mongrel server')
@mock_mongrel.stubs(:register)
@mock_model = mock('indirected model')
@@ -33,7 +35,7 @@ describe Puppet::Network::HTTP::MongrelREST, "when initializing" do
end
end
-describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
+describe "Puppet::Network::HTTP::MongrelREST", "when receiving a request" do
confine "Mongrel is not available" => Puppet.features.mongrel?
before do
@@ -131,6 +133,8 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
end
describe "and determining the request parameters", :shared => true do
+ confine "Mongrel is not available" => Puppet.features.mongrel?
+
before do
@mock_request.stubs(:params).returns({})
end
@@ -198,6 +202,8 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
end
describe "when finding a model instance" do |variable|
+ confine "Mongrel is not available" => Puppet.features.mongrel?
+
it "should fail to find model if key is not specified" do
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'GET', Mongrel::Const::REQUEST_PATH => '/foo'})
@mock_response.expects(:start).with(404)
@@ -236,6 +242,8 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
end
describe "when destroying a model instance" do |variable|
+ confine "Mongrel is not available" => Puppet.features.mongrel?
+
it "should fail to destroy model if key is not specified" do
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'DELETE', Mongrel::Const::REQUEST_PATH => '/foo'})
@mock_response.expects(:start).with(404)
@@ -281,6 +289,8 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
end
describe "when saving a model instance" do |variable|
+ confine "Mongrel is not available" => Puppet.features.mongrel?
+
it "should fail to save model if data is not specified" do
@mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'PUT', Mongrel::Const::REQUEST_PATH => '/foo'})
@mock_request.stubs(:body).returns('')
@@ -319,6 +329,8 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
end
describe "when searching for model instances" do |variable|
+ confine "Mongrel is not available" => Puppet.features.mongrel?
+
it "should use a common method for determining the request parameters" do
setup_search_request('QUERY_STRING' => 'foo=baz&bar=xyzzy')
@handler.expects(:params).returns(:foo => :baz, :bar => :xyzzy)
diff --git a/spec/unit/network/http/webrick.rb b/spec/unit/network/http/webrick.rb
index e3c3b81c0..7e5084bbc 100755
--- a/spec/unit/network/http/webrick.rb
+++ b/spec/unit/network/http/webrick.rb
@@ -5,6 +5,7 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/network/http'
+require 'puppet/network/http/webrick'
describe Puppet::Network::HTTP::WEBrick, "after initializing" do
it "should not be listening" do
diff --git a/spec/unit/network/http/webrick/rest.rb b/spec/unit/network/http/webrick/rest.rb
index 45e5f0bd2..17d47e54c 100755
--- a/spec/unit/network/http/webrick/rest.rb
+++ b/spec/unit/network/http/webrick/rest.rb
@@ -2,6 +2,7 @@
require File.dirname(__FILE__) + '/../../../../spec_helper'
require 'puppet/network/http'
+require 'puppet/network/http/webrick/rest'
describe Puppet::Network::HTTP::WEBrickREST, "when initializing" do
before do