summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorNick Lewis <nick@puppetlabs.com>2010-10-28 12:49:19 -0700
committerNick Lewis <nick@puppetlabs.com>2011-03-04 13:48:11 -0800
commit8bd80a99a259e6409a9ac0a8a60325f94b5c5e9d (patch)
tree5e3c32fd2be0f5934a01de79cdb397681f1e9804 /spec/unit
parentc65ef89e533e73d0f9ec34244be630bae00b53d5 (diff)
downloadpuppet-8bd80a99a259e6409a9ac0a8a60325f94b5c5e9d.tar.gz
puppet-8bd80a99a259e6409a9ac0a8a60325f94b5c5e9d.tar.xz
puppet-8bd80a99a259e6409a9ac0a8a60325f94b5c5e9d.zip
(#5148) Add support for PSON to facts
Previously, facts could be fetched via the REST API in PSON, but came back as the to_s representation of a Ruby object, rather than as proper PSON data. This patch adds to_pson and from_pson to facts, so they can be properly used with PSON.
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/node/facts_spec.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/unit/node/facts_spec.rb b/spec/unit/node/facts_spec.rb
index 394db7913..19049e9bf 100755
--- a/spec/unit/node/facts_spec.rb
+++ b/spec/unit/node/facts_spec.rb
@@ -109,5 +109,29 @@ describe Puppet::Node::Facts, "when indirecting" do
facts = Puppet::Node::Facts.new("me", "one" => "two", "three" => "four")
facts.values[:_timestamp].should be_instance_of(Time)
end
+
+ describe "using pson" do
+ before :each do
+ @timestamp = Time.parse("Thu Oct 28 11:16:31 -0700 2010")
+ @expiration = Time.parse("Thu Oct 28 11:21:31 -0700 2010")
+ end
+
+ it "should accept properly formatted pson" do
+ pson = %Q({"name": "foo", "expiration": "#{@expiration}", "timestamp": "#{@timestamp}", "values": {"a": "1", "b": "2", "c": "3"}})
+ format = Puppet::Network::FormatHandler.format('pson')
+ facts = format.intern(Puppet::Node::Facts,pson)
+ facts.name.should == 'foo'
+ facts.expiration.should == @expiration
+ facts.values.should == {'a' => '1', 'b' => '2', 'c' => '3', :_timestamp => @timestamp}
+ end
+
+ it "should generate properly formatted pson" do
+ Time.stubs(:now).returns(@timestamp)
+ facts = Puppet::Node::Facts.new("foo", {'a' => 1, 'b' => 2, 'c' => 3})
+ facts.expiration = @expiration
+ pson = PSON.parse(facts.to_pson)
+ pson.should == {"name"=>"foo", "timestamp"=>"Thu Oct 28 11:16:31 -0700 2010", "expiration"=>"Thu Oct 28 11:21:31 -0700 2010", "values"=>{"a"=>1, "b"=>2, "c"=>3}}
+ end
+ end
end
end