summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xlib/puppet/node/facts.rb15
-rwxr-xr-xspec/unit/node/facts_spec.rb14
2 files changed, 23 insertions, 6 deletions
diff --git a/lib/puppet/node/facts.rb b/lib/puppet/node/facts.rb
index 577b62b62..8d0a03474 100755
--- a/lib/puppet/node/facts.rb
+++ b/lib/puppet/node/facts.rb
@@ -61,18 +61,21 @@ class Puppet::Node::Facts
def self.from_pson(data)
result = new(data['name'], data['values'])
- result.timestamp = Time.parse(data['timestamp'])
- result.expiration = Time.parse(data['expiration'])
+ result.timestamp = Time.parse(data['timestamp']) if data['timestamp']
+ result.expiration = Time.parse(data['expiration']) if data['expiration']
result
end
def to_pson(*args)
- {
- 'expiration' => expiration,
+ result = {
'name' => name,
- 'timestamp' => timestamp,
'values' => strip_internal,
- }.to_pson(*args)
+ }
+
+ result['timestamp'] = timestamp if timestamp
+ result['expiration'] = expiration if expiration
+
+ result.to_pson(*args)
end
# Add internal data to the facts for storage.
diff --git a/spec/unit/node/facts_spec.rb b/spec/unit/node/facts_spec.rb
index efaa76e12..6d2b0a7ac 100755
--- a/spec/unit/node/facts_spec.rb
+++ b/spec/unit/node/facts_spec.rb
@@ -128,6 +128,20 @@ describe Puppet::Node::Facts, "when indirecting" do
result['timestamp'].should == facts.timestamp.to_s
result['expiration'].should == facts.expiration.to_s
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