summaryrefslogtreecommitdiffstats
path: root/spec/unit/node
diff options
context:
space:
mode:
authorJosh Cooper <josh@puppetlabs.com>2011-04-21 14:37:50 -0700
committerJosh Cooper <josh@puppetlabs.com>2011-04-21 14:37:50 -0700
commit01f610bb223b435dc52f491260af3ea002930102 (patch)
tree93565136d5ef2b4156fdd64476792e441bcfbb4e /spec/unit/node
parentac428b9557e2da251e4b51e48de844833ca0aa2a (diff)
parentfc66e98b84b9a16728af054485883334a5887cca (diff)
Merge branch 'next'
Diffstat (limited to 'spec/unit/node')
-rwxr-xr-xspec/unit/node/facts_spec.rb34
1 files changed, 30 insertions, 4 deletions
diff --git a/spec/unit/node/facts_spec.rb b/spec/unit/node/facts_spec.rb
index a130ae3f8..07f5f7e1b 100755
--- a/spec/unit/node/facts_spec.rb
+++ b/spec/unit/node/facts_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env rspec
require 'spec_helper'
-
+require 'matchers/json'
require 'puppet/node/facts'
describe Puppet::Node::Facts, "when indirecting" do
@@ -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'
@@ -122,8 +126,30 @@ describe Puppet::Node::Facts, "when indirecting" 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"=>@timestamp.to_s, "expiration"=>@expiration.to_s, "values"=>{"a"=>1, "b"=>2, "c"=>3}}
+ result = PSON.parse(facts.to_pson)
+ result.name.should == facts.name
+ result.values.should == facts.values
+ result.timestamp.should == facts.timestamp
+ result.expiration.should == facts.expiration
+ result.type.should == Puppet::Node::Facts
+ end
+
+ it "should not include nil values" do
+ facts = Puppet::Node::Facts.new("foo", {'a' => 1, 'b' => 2, 'c' => 3})
+
+ # XXX:LAK For some reason this is resurrection the full instance, instead
+ # of just returning the hash. This code works, but I can't figure out what's
+ # going on.
+ newfacts = PSON.parse(facts.to_pson)
+ newfacts.expiration.should be_nil
+ 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