diff options
| author | Markus Roberts <Markus@reality.com> | 2009-10-09 15:23:19 -0700 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2009-10-17 12:23:33 +1100 |
| commit | bca3b70437666a8b840af032cab20fc1ea4f18a2 (patch) | |
| tree | 0cde5cd7b39fc5a5e41b636d1f55a7ed71d6518b /spec/integration | |
| parent | ce46be5773656f68eddc7edd6212e283b46f9320 (diff) | |
| download | puppet-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')
| -rwxr-xr-x | spec/integration/application/puppet.rb | 8 | ||||
| -rwxr-xr-x | spec/integration/defaults.rb | 4 | ||||
| -rwxr-xr-x | spec/integration/indirector/catalog/queue.rb | 10 | ||||
| -rwxr-xr-x | spec/integration/network/formats.rb | 72 | ||||
| -rwxr-xr-x | spec/integration/resource/catalog.rb | 8 |
5 files changed, 51 insertions, 51 deletions
diff --git a/spec/integration/application/puppet.rb b/spec/integration/application/puppet.rb index e3f8fb9fc..1342f3c5f 100755 --- a/spec/integration/application/puppet.rb +++ b/spec/integration/application/puppet.rb @@ -10,16 +10,16 @@ describe "Puppet" do include PuppetSpec::Files describe "when applying provided catalogs" do - confine "JSON library is missing; cannot test applying catalogs" => Puppet.features.json? - it "should be able to apply catalogs provided in a file in json" do - file_to_create = tmpfile("json_catalog") + confine "PSON library is missing; cannot test applying catalogs" => Puppet.features.pson? + it "should be able to apply catalogs provided in a file in pson" do + file_to_create = tmpfile("pson_catalog") catalog = Puppet::Resource::Catalog.new resource = Puppet::Resource.new(:file, file_to_create, :content => "my stuff") catalog.add_resource resource manifest = tmpfile("manifest") - File.open(manifest, "w") { |f| f.print catalog.to_json } + File.open(manifest, "w") { |f| f.print catalog.to_pson } puppet = Puppet::Application[:puppet] puppet.options[:catalog] = manifest diff --git a/spec/integration/defaults.rb b/spec/integration/defaults.rb index c38a1a14b..fb00f8646 100755 --- a/spec/integration/defaults.rb +++ b/spec/integration/defaults.rb @@ -89,8 +89,8 @@ describe "Puppet defaults" do end end - it "should default to json for the preferred serialization format" do - Puppet.settings.value(:preferred_serialization_format).should == "json" + it "should default to pson for the preferred serialization format" do + Puppet.settings.value(:preferred_serialization_format).should == "pson" end describe "when enabling storeconfigs" do diff --git a/spec/integration/indirector/catalog/queue.rb b/spec/integration/indirector/catalog/queue.rb index bf121811c..5a781c1a8 100755 --- a/spec/integration/indirector/catalog/queue.rb +++ b/spec/integration/indirector/catalog/queue.rb @@ -6,7 +6,7 @@ require 'puppet/resource/catalog' describe "Puppet::Resource::Catalog::Queue" do - confine "Missing json support; cannot test queue" => Puppet.features.json? + confine "Missing pson support; cannot test queue" => Puppet.features.pson? before do Puppet::Resource::Catalog.indirection.terminus(:queue) @@ -23,13 +23,13 @@ describe "Puppet::Resource::Catalog::Queue" do after { Puppet.settings.clear } - it "should render catalogs to json and send them via the queue client when catalogs are saved" do + it "should render catalogs to pson and send them via the queue client when catalogs are saved" do terminus = Puppet::Resource::Catalog.indirection.terminus(:queue) client = mock 'client' terminus.stubs(:client).returns client - client.expects(:send_message).with(:catalog, @catalog.to_json) + client.expects(:send_message).with(:catalog, @catalog.to_pson) request = Puppet::Indirector::Request.new(:catalog, :save, "foo", :instance => @catalog) @@ -40,9 +40,9 @@ describe "Puppet::Resource::Catalog::Queue" do client = mock 'client' Puppet::Resource::Catalog::Queue.stubs(:client).returns client - json = @catalog.to_json + pson = @catalog.to_pson - client.expects(:subscribe).with(:catalog).yields(json) + client.expects(:subscribe).with(:catalog).yields(pson) Puppet.expects(:err).never 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 diff --git a/spec/integration/resource/catalog.rb b/spec/integration/resource/catalog.rb index 9c7c37d8e..f4004451d 100755 --- a/spec/integration/resource/catalog.rb +++ b/spec/integration/resource/catalog.rb @@ -6,10 +6,10 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe Puppet::Resource::Catalog do - describe "when json is available" do - confine "JSON library is missing" => Puppet.features.json? - it "should support json" do - Puppet::Resource::Catalog.supported_formats.should be_include(:json) + describe "when pson is available" do + confine "PSON library is missing" => Puppet.features.pson? + it "should support pson" do + Puppet::Resource::Catalog.supported_formats.should be_include(:pson) end end |
