The string format no longer provides any support methods,
which means that I had to create to_multiple_s and from_multiple_s
methods on the SSL classes. I created them in the base class
and tested them just in the cert class.
Signed-off-by: Luke Kanies <[EMAIL PROTECTED]>
---
lib/puppet/network/format.rb | 4 +++
lib/puppet/network/formats.rb | 18 +-------------
lib/puppet/ssl/base.rb | 11 ++++++++
spec/integration/network/formats.rb | 19 +++++++++++++++
spec/unit/network/formats.rb | 32 -------------------------
spec/unit/ssl/certificate.rb | 44 +++++++++++++++++++++++++++--------
6 files changed, 69 insertions(+), 59 deletions(-)
create mode 100755 spec/integration/network/formats.rb
diff --git a/lib/puppet/network/format.rb b/lib/puppet/network/format.rb
index a4515e3..5f259fa 100644
--- a/lib/puppet/network/format.rb
+++ b/lib/puppet/network/format.rb
@@ -61,6 +61,10 @@ class Puppet::Network::Format
klass.instance_methods.include?(render_method)
end
+ def to_s
+ "Puppet::Network::Format[%s]" % name
+ end
+
private
attr_reader :intern_method, :render_method, :intern_multiple_method,
:render_multiple_method
diff --git a/lib/puppet/network/formats.rb b/lib/puppet/network/formats.rb
index e11748c..8e4c59f 100644
--- a/lib/puppet/network/formats.rb
+++ b/lib/puppet/network/formats.rb
@@ -53,20 +53,4 @@ Puppet::Network::FormatHandler.create(:marshal, :mime =>
"text/marshal") do
end
end
-Puppet::Network::FormatHandler.create(:s, :mime => "text/plain") do
- # For now, use the YAML separator.
- SEPARATOR = "\n---\n"
-
- def intern_multiple(klass, text)
- text.split(SEPARATOR).collect { |inst| intern(klass, inst) }
- end
-
- def render_multiple(instances)
- instances.collect { |inst| render(inst) }.join(SEPARATOR)
- end
-
- # Everything's supported
- def supported?(klass)
- true
- end
-end
+Puppet::Network::FormatHandler.create(:s, :mime => "text/plain")
diff --git a/lib/puppet/ssl/base.rb b/lib/puppet/ssl/base.rb
index 08efb31..a005bfa 100644
--- a/lib/puppet/ssl/base.rb
+++ b/lib/puppet/ssl/base.rb
@@ -2,6 +2,17 @@ require 'puppet/ssl'
# The base class for wrapping SSL instances.
class Puppet::SSL::Base
+ # For now, use the YAML separator.
+ SEPARATOR = "\n---\n"
+
+ def self.from_multiple_s(text)
+ text.split(SEPARATOR).collect { |inst| from_s(inst) }
+ end
+
+ def self.to_multiple_s(instances)
+ instances.collect { |inst| inst.to_s }.join(SEPARATOR)
+ end
+
def self.wraps(klass)
@wrapped_class = klass
end
diff --git a/spec/integration/network/formats.rb
b/spec/integration/network/formats.rb
new file mode 100755
index 0000000..0cfbadd
--- /dev/null
+++ b/spec/integration/network/formats.rb
@@ -0,0 +1,19 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/network/formats'
+
+describe Puppet::Network::FormatHandler.format(:s) do
+ before do
+ @format = Puppet::Network::FormatHandler.format(:s)
+ end
+
+ it "should support certificates" do
+ @format.should be_supported(Puppet::SSL::Certificate)
+ end
+
+ it "should not support catalogs" do
+ @format.should_not be_supported(Puppet::Node::Catalog)
+ end
+end
diff --git a/spec/unit/network/formats.rb b/spec/unit/network/formats.rb
index d5967c6..f749336 100755
--- a/spec/unit/network/formats.rb
+++ b/spec/unit/network/formats.rb
@@ -98,37 +98,5 @@ describe "Puppet Network Format" do
it "should have its mimetype set to text/plain" do
@text.mime.should == "text/plain"
end
-
- it "should fail if the instance does not respond to 'to_s'" do
- instance = mock 'nope'
- instance.expects(:to_s).never
- lambda { @text.render(instance) }.should
raise_error(NotImplementedError)
- end
-
- it "should render by calling 'to_s' on the instance" do
- # Use an instance that responds to 'to_s'
- instance = "foo"
- instance.expects(:to_s).returns "string"
- @text.render(instance).should == "string"
- end
-
- it "should render multiple instances by calling 'to_s' on each
instance and joining the results with '\\n---\\n'" do
- instances = ["string1", 'string2']
-
- @text.render_multiple(instances).should == "string1\n---\nstring2"
- end
-
- it "should intern by calling 'from_s' on the class" do
- text = "foo"
- String.expects(:from_s).with(text).returns "bar"
- @text.intern(String, text).should == "bar"
- end
-
- it "should intern multiples by splitting on '\\n---\\n' and converting
each string to an instance" do
- text = "foo\n---\nbar"
- String.expects(:from_s).with("foo").returns "FOO"
- String.expects(:from_s).with("bar").returns "BAR"
- @text.intern_multiple(String, text).should == ["FOO", "BAR"]
- end
end
end
diff --git a/spec/unit/ssl/certificate.rb b/spec/unit/ssl/certificate.rb
index 34868dc..92b7f2c 100755
--- a/spec/unit/ssl/certificate.rb
+++ b/spec/unit/ssl/certificate.rb
@@ -41,6 +41,40 @@ describe Puppet::SSL::Certificate do
@class.from_s("my certificate")
end
+
+ it "should create multiple certificate instances when asked" do
+ cert1 = stub 'cert1'
+ @class.expects(:from_s).with("cert1").returns cert1
+ cert2 = stub 'cert2'
+ @class.expects(:from_s).with("cert2").returns cert2
+
+ @class.from_multiple_s("cert1\n---\ncert2").should == [cert1,
cert2]
+ end
+ end
+
+ describe "when converting to a string" do
+ before do
+ @certificate = @class.new("myname")
+ end
+
+ it "should return an empty string when it has no certificate" do
+ @certificate.to_s.should == ""
+ end
+
+ it "should convert the certificate to pem format" do
+ certificate = mock 'certificate', :to_pem => "pem"
+ @certificate.content = certificate
+ @certificate.to_s.should == "pem"
+ end
+
+ it "should be able to convert multiple instances to a string" do
+ cert2 = @class.new("foo")
+ @certificate.expects(:to_s).returns "cert1"
+ cert2.expects(:to_s).returns "cert2"
+
+ @class.to_multiple_s([EMAIL PROTECTED], cert2]).should ==
"cert1\n---\ncert2"
+
+ end
end
describe "when managing instances" do
@@ -84,16 +118,6 @@ describe Puppet::SSL::Certificate do
@certificate.content.should equal(certificate)
end
- it "should return an empty string when converted to a string with no
certificate" do
- @certificate.to_s.should == ""
- end
-
- it "should convert the certificate to pem format when converted to a
string" do
- certificate = mock 'certificate', :to_pem => "pem"
- @certificate.content = certificate
- @certificate.to_s.should == "pem"
- end
-
it "should have a :to_text method that it delegates to the actual key"
do
real_certificate = mock 'certificate'
real_certificate.expects(:to_text).returns "certificatetext"
--
1.5.3.7
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---