summaryrefslogtreecommitdiffstats
path: root/spec/unit/network
diff options
context:
space:
mode:
authorLuke Kanies <luke@reductivelabs.com>2009-12-21 16:23:44 -0800
committerLuke Kanies <luke@reductivelabs.com>2009-12-21 16:23:44 -0800
commit740fd6b301af89ab3aad89bca183ad1fcdc24ac4 (patch)
treef34617a229509c373d28d67abb453e7ae2136c39 /spec/unit/network
parent8971d8beae2c409f9052f27c3f80ad3bdfff4de2 (diff)
parent4a06379f8770c164e42bcc410d874076c6e95f24 (diff)
Merge branch '0.25.x'
Conflicts: lib/puppet/agent.rb lib/puppet/application/puppetd.rb lib/puppet/parser/ast/leaf.rb lib/puppet/util/rdoc/parser.rb
Diffstat (limited to 'spec/unit/network')
-rw-r--r--spec/unit/network/authstore.rb30
-rwxr-xr-xspec/unit/network/format_handler.rb36
-rwxr-xr-xspec/unit/network/formats.rb85
-rwxr-xr-xspec/unit/network/http/webrick.rb4
-rwxr-xr-xspec/unit/network/rights.rb2
5 files changed, 146 insertions, 11 deletions
diff --git a/spec/unit/network/authstore.rb b/spec/unit/network/authstore.rb
index 55b2c7bbc..4087b28ed 100644
--- a/spec/unit/network/authstore.rb
+++ b/spec/unit/network/authstore.rb
@@ -4,6 +4,36 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/network/authconfig'
+describe Puppet::Network::AuthStore do
+ describe "when checking if the acl has some entries" do
+ before :each do
+ @authstore = Puppet::Network::AuthStore.new
+ end
+
+ it "should be empty if no ACE have been entered" do
+ @authstore.should be_empty
+ end
+
+ it "should not be empty if it is a global allow" do
+ @authstore.allow('*')
+
+ @authstore.should_not be_empty
+ end
+
+ it "should not be empty if at least one allow has been entered" do
+ @authstore.allow('1.1.1.*')
+
+ @authstore.should_not be_empty
+ end
+
+ it "should not be empty if at least one deny has been entered" do
+ @authstore.deny('1.1.1.*')
+
+ @authstore.should_not be_empty
+ end
+ end
+end
+
describe Puppet::Network::AuthStore::Declaration do
['100.101.99.98','100.100.100.100','1.2.3.4','11.22.33.44'].each { |ip|
diff --git a/spec/unit/network/format_handler.rb b/spec/unit/network/format_handler.rb
index 8a79a58b3..110effe09 100755
--- a/spec/unit/network/format_handler.rb
+++ b/spec/unit/network/format_handler.rb
@@ -49,15 +49,35 @@ describe Puppet::Network::FormatHandler do
FormatTester.supported_formats.should == [:four, :two, :three, :one]
end
- it "should always put the preferred serialization format first if it is supported" do
- one = stub 'supported', :supported? => true, :name => :one, :weight => 1
- two = stub 'supported', :supported? => true, :name => :two, :weight => 6
- Puppet.settings.expects(:value).with(:preferred_serialization_format).returns :one
- Puppet::Network::FormatHandler.stubs(:formats).returns [:one, :two]
- Puppet::Network::FormatHandler.stubs(:format).with(:one).returns one
- Puppet::Network::FormatHandler.stubs(:format).with(:two).returns two
- FormatTester.supported_formats.should == [:one, :two]
+ describe "with a preferred serialization format setting" do
+ before do
+ one = stub 'supported', :supported? => true, :name => :one, :weight => 1
+ two = stub 'supported', :supported? => true, :name => :two, :weight => 6
+ Puppet::Network::FormatHandler.stubs(:formats).returns [:one, :two]
+ Puppet::Network::FormatHandler.stubs(:format).with(:one).returns one
+ Puppet::Network::FormatHandler.stubs(:format).with(:two).returns two
+ end
+ describe "that is supported" do
+ before do
+ Puppet.settings.expects(:value).with(:preferred_serialization_format).returns :one
+ end
+ it "should return the preferred serialization format first" do
+ FormatTester.supported_formats.should == [:one, :two]
+ end
+ end
+ describe "that is not supported" do
+ before do
+ Puppet.settings.expects(:value).with(:preferred_serialization_format).returns :unsupported
+ end
+ it "should still return the default format first" do
+ FormatTester.supported_formats.should == [:two, :one]
+ end
+ it "should log a warning" do
+ Puppet.expects(:warning)
+ FormatTester.supported_formats
+ end
+ end
end
it "should return the first format as the default format" do
diff --git a/spec/unit/network/formats.rb b/spec/unit/network/formats.rb
index de2e0afe3..b1ef9ec53 100755
--- a/spec/unit/network/formats.rb
+++ b/spec/unit/network/formats.rb
@@ -90,6 +90,91 @@ describe "Puppet Network Format" do
end
end
+ describe "base64 compressed yaml" do
+ before do
+ @yaml = Puppet::Network::FormatHandler.format(:b64_zlib_yaml)
+ end
+
+ it "should have its mime type set to text/b64_zlib_yaml" do
+ @yaml.mime.should == "text/b64_zlib_yaml"
+ end
+
+ it "should render by calling 'to_yaml' on the instance" do
+ instance = mock 'instance'
+ instance.expects(:to_yaml).returns "foo"
+ @yaml.render(instance)
+ end
+
+ it "should fixup generated yaml on render" do
+ instance = mock 'instance', :to_yaml => "foo"
+
+ @yaml.expects(:fixup).with("foo").returns "bar"
+
+ @yaml.render(instance)
+ end
+
+ it "should encode generated yaml on render" do
+ instance = mock 'instance', :to_yaml => "foo"
+
+ @yaml.expects(:encode).with("foo").returns "bar"
+
+ @yaml.render(instance).should == "bar"
+ end
+
+ it "should render multiple instances by calling 'to_yaml' on the array" do
+ instances = [mock('instance')]
+ instances.expects(:to_yaml).returns "foo"
+ @yaml.render_multiple(instances)
+ end
+
+ it "should fixup generated yaml on render" do
+ instances = [mock('instance')]
+ instances.stubs(:to_yaml).returns "foo"
+
+ @yaml.expects(:fixup).with("foo").returns "bar"
+
+ @yaml.render(instances)
+ end
+
+ it "should encode generated yaml on render" do
+ instances = [mock('instance')]
+ instances.stubs(:to_yaml).returns "foo"
+
+ @yaml.expects(:encode).with("foo").returns "bar"
+
+ @yaml.render(instances).should == "bar"
+ end
+
+ it "should intern by calling decode" do
+ text = "foo"
+ @yaml.expects(:decode).with("foo").returns "bar"
+ @yaml.intern(String, text).should == "bar"
+ end
+
+ it "should intern multiples by calling 'decode'" do
+ text = "foo"
+ @yaml.expects(:decode).with("foo").returns "bar"
+ @yaml.intern_multiple(String, text).should == "bar"
+ end
+
+ it "should decode by base64 decoding, uncompressing and Yaml loading" do
+ Base64.expects(:decode64).with("zorg").returns "foo"
+ Zlib::Inflate.expects(:inflate).with("foo").returns "baz"
+ YAML.expects(:load).with("baz").returns "bar"
+ @yaml.decode("zorg").should == "bar"
+ end
+
+ it "should encode by compressing and base64 encoding" do
+ Zlib::Deflate.expects(:deflate).with("foo", Zlib::BEST_COMPRESSION).returns "bar"
+ Base64.expects(:encode64).with("bar").returns "baz"
+ @yaml.encode("foo").should == "baz"
+ end
+
+ it "should fixup incorrect yaml to correct" do
+ @yaml.fixup("&id004 !ruby/object:Puppet::Relationship ?").should == "? &id004 !ruby/object:Puppet::Relationship"
+ end
+ end
+
it "should include a marshal format" do
Puppet::Network::FormatHandler.format(:marshal).should_not be_nil
end
diff --git a/spec/unit/network/http/webrick.rb b/spec/unit/network/http/webrick.rb
index 1b76341ba..fca2e075e 100755
--- a/spec/unit/network/http/webrick.rb
+++ b/spec/unit/network/http/webrick.rb
@@ -15,7 +15,7 @@ end
describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
before do
- @mock_webrick = stub('webrick', :[] => {})
+ @mock_webrick = stub('webrick', :[] => {}, :listeners => [])
[:mount, :start, :shutdown].each {|meth| @mock_webrick.stubs(meth)}
WEBrick::HTTPServer.stubs(:new).returns(@mock_webrick)
@server = Puppet::Network::HTTP::WEBrick.new
@@ -162,7 +162,7 @@ end
describe Puppet::Network::HTTP::WEBrick, "when turning off listening" do
before do
- @mock_webrick = stub('webrick', :[] => {})
+ @mock_webrick = stub('webrick', :[] => {}, :listeners => [])
[:mount, :start, :shutdown].each {|meth| @mock_webrick.stubs(meth)}
WEBrick::HTTPServer.stubs(:new).returns(@mock_webrick)
@server = Puppet::Network::HTTP::WEBrick.new
diff --git a/spec/unit/network/rights.rb b/spec/unit/network/rights.rb
index 244fa18c8..7f00891ac 100755
--- a/spec/unit/network/rights.rb
+++ b/spec/unit/network/rights.rb
@@ -391,7 +391,7 @@ describe Puppet::Network::Rights do
end
it "should match as a regex" do
- @acl.match?("this shoud work.rb").should_not be_nil
+ @acl.match?("this should work.rb").should_not be_nil
end
it "should return nil if no match" do