summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2009-08-02 11:13:07 -0700
committerJames Turnbull <james@lovedthanlost.net>2009-08-03 07:40:55 +1000
commit1f8ef6086cc1bb27035cc2534fac781a0349bfb5 (patch)
tree3bc98e8c3c72d26c3a881dc52332ad2f79df3c44
parent11c0fb77230ea5ba28bfe86a1c2a1469095b6c70 (diff)
downloadpuppet-1f8ef6086cc1bb27035cc2534fac781a0349bfb5.tar.gz
puppet-1f8ef6086cc1bb27035cc2534fac781a0349bfb5.tar.xz
puppet-1f8ef6086cc1bb27035cc2534fac781a0349bfb5.zip
Fixes #2444 - Various JSON test failures
-rwxr-xr-xspec/integration/network/formats.rb20
1 files changed, 17 insertions, 3 deletions
diff --git a/spec/integration/network/formats.rb b/spec/integration/network/formats.rb
index c3b97bc0b..3ea26f534 100755
--- a/spec/integration/network/formats.rb
+++ b/spec/integration/network/formats.rb
@@ -7,7 +7,7 @@ require 'puppet/network/formats'
class JsonIntTest
attr_accessor :string
def ==(other)
- string == other.string
+ other.class == self.class and string == other.string
end
def self.from_json(data)
@@ -24,6 +24,11 @@ class JsonIntTest
'data' => [@string]
}.to_json(*args)
end
+
+ def self.canonical_order(s)
+ s.gsub(/\{"data":\[(.*?)\],"json_class":"JsonIntTest"\}/,'{"json_class":"JsonIntTest","data":[\1]}')
+ end
+
end
describe Puppet::Network::FormatHandler.format(:s) do
@@ -58,15 +63,24 @@ describe Puppet::Network::FormatHandler.format(:json) do
it "should be able to render an instance to json" do
instance = JsonIntTest.new("foo")
+ JsonIntTest.canonical_order(@json.render(instance)).should == JsonIntTest.canonical_order('{"json_class":"JsonIntTest","data":["foo"]}' )
+ end
- @json.render(instance).should == '{"json_class":"JsonIntTest","data":["foo"]}'
+ it "should be able to render arrays to json" do
+ @json.render([1,2]).should == '[1,2]'
+ end
+
+ it "should be able to render arrays containing hashes to json" do
+ @json.render([{"one"=>1},{"two"=>2}]).should == '[{"one":1},{"two":2}]'
end
it "should be able to render multiple instances to json" do
+ Puppet.features.add(:json, :libs => ["json"])
+
one = JsonIntTest.new("one")
two = JsonIntTest.new("two")
- @json.render([one, two]).should == '[{"json_class":"JsonIntTest","data":["one"]},{"json_class":"JsonIntTest","data":["two"]}]'
+ JsonIntTest.canonical_order(@json.render([one,two])).should == JsonIntTest.canonical_order('[{"json_class":"JsonIntTest","data":["one"]},{"json_class":"JsonIntTest","data":["two"]}]')
end
it "should be able to intern json into an instance" do