summaryrefslogtreecommitdiffstats
path: root/spec/integration
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-05-06 14:32:25 -0700
committerJames Turnbull <james@lovedthanlost.net>2009-06-06 19:53:35 +1000
commit7f322b315a7890f1b3cee035d023f09814cc6075 (patch)
tree014201a062017a3a13f4c3e6c547f8d0a309f1d8 /spec/integration
parent7666597edc335055275569f5626a897453402d5b (diff)
downloadpuppet-7f322b315a7890f1b3cee035d023f09814cc6075.tar.gz
puppet-7f322b315a7890f1b3cee035d023f09814cc6075.tar.xz
puppet-7f322b315a7890f1b3cee035d023f09814cc6075.zip
Adding a JSON format
Also making some log messages more informative.
Diffstat (limited to 'spec/integration')
-rwxr-xr-xspec/integration/network/formats.rb73
-rwxr-xr-xspec/integration/resource/catalog.rb4
2 files changed, 77 insertions, 0 deletions
diff --git a/spec/integration/network/formats.rb b/spec/integration/network/formats.rb
index 2ec4cb9e8..c3b97bc0b 100755
--- a/spec/integration/network/formats.rb
+++ b/spec/integration/network/formats.rb
@@ -4,6 +4,28 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/network/formats'
+class JsonIntTest
+ attr_accessor :string
+ def ==(other)
+ string == other.string
+ end
+
+ def self.from_json(data)
+ new(data[0])
+ end
+
+ def initialize(string)
+ @string = string
+ end
+
+ def to_json(*args)
+ {
+ 'json_class' => self.class.name,
+ 'data' => [@string]
+ }.to_json(*args)
+ end
+end
+
describe Puppet::Network::FormatHandler.format(:s) do
before do
@format = Puppet::Network::FormatHandler.format(:s)
@@ -17,3 +39,54 @@ describe Puppet::Network::FormatHandler.format(:s) do
@format.should_not be_supported(Puppet::Resource::Catalog)
end
end
+
+describe Puppet::Network::FormatHandler.format(:json) do
+ describe "when json is absent" do
+ confine "'json' library is prsent" => (! Puppet.features.json?)
+
+ it "should not be suitable" do
+ @json.should_not be_suitable
+ end
+ end
+
+ describe "when json is available" do
+ confine "Missing 'json' library" => Puppet.features.json?
+
+ before do
+ @json = Puppet::Network::FormatHandler.format(:json)
+ end
+
+ it "should be able to render an instance to json" do
+ instance = JsonIntTest.new("foo")
+
+ @json.render(instance).should == '{"json_class":"JsonIntTest","data":["foo"]}'
+ end
+
+ it "should be able to render multiple instances to json" do
+ one = JsonIntTest.new("one")
+ two = JsonIntTest.new("two")
+
+ @json.render([one, two]).should == '[{"json_class":"JsonIntTest","data":["one"]},{"json_class":"JsonIntTest","data":["two"]}]'
+ end
+
+ it "should be able to intern json into an instance" do
+ @json.intern(JsonIntTest, '{"json_class":"JsonIntTest","data":["foo"]}').should == JsonIntTest.new("foo")
+ end
+
+ it "should be able to intern json with no class information into an instance" do
+ @json.intern(JsonIntTest, '["foo"]').should == JsonIntTest.new("foo")
+ end
+
+ it "should be able to intern multiple instances from json" do
+ @json.intern_multiple(JsonIntTest, '[{"json_class": "JsonIntTest", "data": ["one"]},{"json_class": "JsonIntTest", "data": ["two"]}]').should == [
+ JsonIntTest.new("one"), JsonIntTest.new("two")
+ ]
+ end
+
+ it "should be able to intern multiple instances from json with no class information" do
+ @json.intern_multiple(JsonIntTest, '[["one"],["two"]]').should == [
+ JsonIntTest.new("one"), JsonIntTest.new("two")
+ ]
+ end
+ end
+end
diff --git a/spec/integration/resource/catalog.rb b/spec/integration/resource/catalog.rb
index db25dab67..11bdb56f6 100755
--- a/spec/integration/resource/catalog.rb
+++ b/spec/integration/resource/catalog.rb
@@ -6,6 +6,10 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Resource::Catalog do
+ it "should support json" do
+ Puppet::Resource::Catalog.supported_formats.should be_include(:json)
+ end
+
describe "when using the indirector" do
after { Puppet::Util::Cacher.expire }
before do