summaryrefslogtreecommitdiffstats
path: root/spec/integration/network
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2009-10-09 15:23:19 -0700
committerJames Turnbull <james@lovedthanlost.net>2009-10-17 12:23:33 +1100
commitbca3b70437666a8b840af032cab20fc1ea4f18a2 (patch)
tree0cde5cd7b39fc5a5e41b636d1f55a7ed71d6518b /spec/integration/network
parentce46be5773656f68eddc7edd6212e283b46f9320 (diff)
downloadpuppet-bca3b70437666a8b840af032cab20fc1ea4f18a2.tar.gz
puppet-bca3b70437666a8b840af032cab20fc1ea4f18a2.tar.xz
puppet-bca3b70437666a8b840af032cab20fc1ea4f18a2.zip
Bundling of pure ruby json lib as "pson"
Bundeling and renaming the pure ruby json library to addresses a number of cross version serliaization bugs (#2615, et al). This patch adds a subset of the files from the json_pure gem to lib/puppet/external/pson (renamed to avoid conflicts with rails) so that we will always have a known-good erialization format available. The pure ruby json gem as distibuted defers to the compiled version if it is installed. This is problematic in some circumstances so the files that have been brought over have been modified to always and only use the bundled version. It's a large patch, so here's a breakdown of the change categories: The majority of the lines are only marginally interesting: * The json lib itself (in lib/puppet/external/pson) make up the bulk of the lines. * Renaming of json to pson make up the second largest group. Somewhat more interesting are the following, which can be located by searching the diffs for the indicated strings: * Adjusting tests to reflect the changes * Changing the encoding/decoding behavior so that nested structures (e.g. resources) don't serialize as escaped strings. This should make it much easier to process the results with external tools, if needed. Search for "to_pson" and "to_pson_data_hash" * Cleaning up the envelope/metadata * Now provides a document_type (as opposed to a ruby class name) by using a symple registration scheme instead of constant lookup (search for "document_type") * Added an api_version (search for "api_version") * Added a hash for document metadata (search for "metadata") * Removing the yaml monkeypatch and instead disabling yaml serialization on ruby 1.8.1 in favor of pson (search for "yaml") * Cleaning up the json/rails feature interaction (they're now totally independent) (search for "feature")
Diffstat (limited to 'spec/integration/network')
-rwxr-xr-xspec/integration/network/formats.rb72
1 files changed, 36 insertions, 36 deletions
diff --git a/spec/integration/network/formats.rb b/spec/integration/network/formats.rb
index 7d0d47ee7..35e797706 100755
--- a/spec/integration/network/formats.rb
+++ b/spec/integration/network/formats.rb
@@ -4,13 +4,13 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/network/formats'
-class JsonIntTest
+class PsonIntTest
attr_accessor :string
def ==(other)
other.class == self.class and string == other.string
end
- def self.from_json(data)
+ def self.from_pson(data)
new(data[0])
end
@@ -18,15 +18,15 @@ class JsonIntTest
@string = string
end
- def to_json(*args)
+ def to_pson(*args)
{
- 'json_class' => self.class.name,
+ 'type' => self.class.name,
'data' => [@string]
- }.to_json(*args)
+ }.to_pson(*args)
end
def self.canonical_order(s)
- s.gsub(/\{"data":\[(.*?)\],"json_class":"JsonIntTest"\}/,'{"json_class":"JsonIntTest","data":[\1]}')
+ s.gsub(/\{"data":\[(.*?)\],"type":"PsonIntTest"\}/,'{"type":"PsonIntTest","data":[\1]}')
end
end
@@ -45,65 +45,65 @@ describe Puppet::Network::FormatHandler.format(:s) do
end
end
-describe Puppet::Network::FormatHandler.format(:json) do
- describe "when json is absent" do
- confine "'json' library is present" => (! Puppet.features.json?)
+describe Puppet::Network::FormatHandler.format(:pson) do
+ describe "when pson is absent" do
+ confine "'pson' library is present" => (! Puppet.features.pson?)
before do
- @json = Puppet::Network::FormatHandler.format(:json)
+ @pson = Puppet::Network::FormatHandler.format(:pson)
end
it "should not be suitable" do
- @json.should_not be_suitable
+ @pson.should_not be_suitable
end
end
- describe "when json is available" do
- confine "Missing 'json' library" => Puppet.features.json?
+ describe "when pson is available" do
+ confine "Missing 'pson' library" => Puppet.features.pson?
before do
- @json = Puppet::Network::FormatHandler.format(:json)
+ @pson = Puppet::Network::FormatHandler.format(:pson)
end
- 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"]}' )
+ it "should be able to render an instance to pson" do
+ instance = PsonIntTest.new("foo")
+ PsonIntTest.canonical_order(@pson.render(instance)).should == PsonIntTest.canonical_order('{"type":"PsonIntTest","data":["foo"]}' )
end
- it "should be able to render arrays to json" do
- @json.render([1,2]).should == '[1,2]'
+ it "should be able to render arrays to pson" do
+ @pson.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}]'
+ it "should be able to render arrays containing hashes to pson" do
+ @pson.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"])
+ it "should be able to render multiple instances to pson" do
+ Puppet.features.add(:pson, :libs => ["pson"])
- one = JsonIntTest.new("one")
- two = JsonIntTest.new("two")
+ one = PsonIntTest.new("one")
+ two = PsonIntTest.new("two")
- JsonIntTest.canonical_order(@json.render([one,two])).should == JsonIntTest.canonical_order('[{"json_class":"JsonIntTest","data":["one"]},{"json_class":"JsonIntTest","data":["two"]}]')
+ PsonIntTest.canonical_order(@pson.render([one,two])).should == PsonIntTest.canonical_order('[{"type":"PsonIntTest","data":["one"]},{"type":"PsonIntTest","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")
+ it "should be able to intern pson into an instance" do
+ @pson.intern(PsonIntTest, '{"type":"PsonIntTest","data":["foo"]}').should == PsonIntTest.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")
+ it "should be able to intern pson with no class information into an instance" do
+ @pson.intern(PsonIntTest, '["foo"]').should == PsonIntTest.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")
+ it "should be able to intern multiple instances from pson" do
+ @pson.intern_multiple(PsonIntTest, '[{"type": "PsonIntTest", "data": ["one"]},{"type": "PsonIntTest", "data": ["two"]}]').should == [
+ PsonIntTest.new("one"), PsonIntTest.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")
+ it "should be able to intern multiple instances from pson with no class information" do
+ @pson.intern_multiple(PsonIntTest, '[["one"],["two"]]').should == [
+ PsonIntTest.new("one"), PsonIntTest.new("two")
]
end
end