From: MarkusQ <[email protected]>

Ticket 2444 actually represents two issues; firstly that the json
tests were written in a way that assumed serialization ordering of
hash elements, and thus would sporadically fail, and secondly that
this failure was masking an actual problem with the json routines.

This patch fixes the ordering assumprion by wrapping the serialized
representations with a function to enforce a canonical order prior
to comparison.

Signed-off-by: MarkusQ <[email protected]>
---
 spec/integration/network/formats.rb |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/spec/integration/network/formats.rb 
b/spec/integration/network/formats.rb
index c3b97bc..77a972b 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
+        string == (other.respond_to? :string) ? other.string : other.inspect
     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,22 @@ 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
+
+        it "should be able to render arrays to json" do
+            @json.render([1,2]).should == '[1,2]'
+        end
 
-            @json.render(instance).should == 
'{"json_class":"JsonIntTest","data":["foo"]}'
+        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
             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
-- 
1.6.0.4


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to