summaryrefslogtreecommitdiffstats
path: root/spec/unit/node_spec.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@puppetlabs.com>2011-04-12 21:41:06 -0700
committerLuke Kanies <luke@puppetlabs.com>2011-07-15 11:16:06 -0700
commitf4acb025f3a125d4c3c359fb6896ac20b36e06ab (patch)
tree8523e88922841e997d0006906232e13fa6e043a1 /spec/unit/node_spec.rb
parent1cbe2ad70eddbf00ef2d3127a9ffcc9f220ee277 (diff)
downloadpuppet-f4acb025f3a125d4c3c359fb6896ac20b36e06ab.tar.gz
puppet-f4acb025f3a125d4c3c359fb6896ac20b36e06ab.tar.xz
puppet-f4acb025f3a125d4c3c359fb6896ac20b36e06ab.zip
Adding json support to Puppet::Node
Reviewed-by: Daniel Pittman <daniel@puppetlabs.com> Reviewed-by: Nick Lewis <nick@puppetlabs.com> Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'spec/unit/node_spec.rb')
-rwxr-xr-xspec/unit/node_spec.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index c15093d90..ae71046f0 100755
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -36,6 +36,69 @@ describe Puppet::Node do
node.environment.name.should == :bar
end
end
+
+ describe "when converting to json" do
+ before do
+ @node = Puppet::Node.new("mynode")
+ end
+
+ it "should provide its name" do
+ PSON.parse(@node.to_pson)['data']['name'].should == "mynode"
+ end
+
+ it "should include the classes if set" do
+ @node.classes = %w{a b c}
+ PSON.parse(@node.to_pson)['data']['classes'].should == %w{a b c}
+ end
+
+ it "should not include the classes if there are none" do
+ PSON.parse(@node.to_pson)['data'].should_not be_include('classes')
+ end
+
+ it "should include parameters if set" do
+ @node.parameters = {"a" => "b", "c" => "d"}
+ PSON.parse(@node.to_pson)['data']['parameters'].should == {"a" => "b", "c" => "d"}
+ end
+
+ it "should not include the parameters if there are none" do
+ PSON.parse(@node.to_pson)['data'].should_not be_include('parameters')
+ end
+
+ it "should include the environment" do
+ @node.environment = "production"
+ PSON.parse(@node.to_pson)['data']['environment'].should == "production"
+ end
+ end
+
+ describe "when converting from json" do
+ before do
+ @node = Puppet::Node.new("mynode")
+ @format = Puppet::Network::FormatHandler.format('pson')
+ end
+
+ def from_json(json)
+ @format.intern(Puppet::Node, json)
+ end
+
+ it "should set its name" do
+ from_json(@node.to_pson).name.should == "mynode"
+ end
+
+ it "should include the classes if set" do
+ @node.classes = %w{a b c}
+ from_json(@node.to_pson).classes.should == %w{a b c}
+ end
+
+ it "should include parameters if set" do
+ @node.parameters = {"a" => "b", "c" => "d"}
+ from_json(@node.to_pson).parameters.should == {"a" => "b", "c" => "d"}
+ end
+
+ it "should include the environment" do
+ @node.environment = "production"
+ from_json(@node.to_pson).environment.name.should == :production
+ end
+ end
end
describe Puppet::Node, "when initializing" do