diff options
author | Luke Kanies <luke@puppetlabs.com> | 2011-04-12 21:01:09 -0700 |
---|---|---|
committer | Luke Kanies <luke@puppetlabs.com> | 2011-04-14 17:07:08 -0700 |
commit | 07a7a68a25eb9b21189751c27f90f972224ea533 (patch) | |
tree | 6e322b248247d6e33e3d25007d79ec71e2de7f06 /spec/unit/node | |
parent | ba9bd88b8b60ebe567a6d78d70782610cc281213 (diff) | |
download | puppet-07a7a68a25eb9b21189751c27f90f972224ea533.tar.gz puppet-07a7a68a25eb9b21189751c27f90f972224ea533.tar.xz puppet-07a7a68a25eb9b21189751c27f90f972224ea533.zip |
Fixing Facts pson methods more resilient
They were currently failing if any values were nil,
which happened a lot.
We also prefer not to include nil values, since it muddies
the json unnecessarily.
Reviewed-by: Daniel Pittman <daniel@puppetlabs.com>
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'spec/unit/node')
-rwxr-xr-x | spec/unit/node/facts_spec.rb | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/spec/unit/node/facts_spec.rb b/spec/unit/node/facts_spec.rb index a130ae3f8..3c7c9d08b 100755 --- a/spec/unit/node/facts_spec.rb +++ b/spec/unit/node/facts_spec.rb @@ -110,7 +110,11 @@ describe Puppet::Node::Facts, "when indirecting" do end it "should accept properly formatted pson" do - pson = %Q({"name": "foo", "expiration": "#{@expiration}", "timestamp": "#{@timestamp}", "values": {"a": "1", "b": "2", "c": "3"}}) + facts = Puppet::Node::Facts.new("foo") + facts.values = {"a" => "1", "b" => "2", "c" => "3"} + facts.expiration = Time.now + #pson = %Q({"document_type": "Puppet::Node::Facts", "data: {"name": "foo", "expiration": "#{@expiration}", "timestamp": "#{@timestamp}", "values": {"a": "1", "b": "2", "c": "3"}}}) + pson = %Q({"data": {"name":"foo", "expiration":"#{@expiration}", "timestamp": "#{@timestamp}", "values":{"a":"1","b":"2","c":"3"}}, "document_type":"Puppet::Node::Facts"}) format = Puppet::Network::FormatHandler.format('pson') facts = format.intern(Puppet::Node::Facts,pson) facts.name.should == 'foo' @@ -125,6 +129,20 @@ describe Puppet::Node::Facts, "when indirecting" do pson = PSON.parse(facts.to_pson) pson.should == {"name"=>"foo", "timestamp"=>@timestamp.to_s, "expiration"=>@expiration.to_s, "values"=>{"a"=>1, "b"=>2, "c"=>3}} end + + it "should not include nil values" do + facts = Puppet::Node::Facts.new("foo", {'a' => 1, 'b' => 2, 'c' => 3}) + pson = PSON.parse(facts.to_pson) + pson.should_not be_include("expiration") + end + + it "should be able to handle nil values" do + pson = %Q({"name": "foo", "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 be_nil + end end end end |