summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorMax Martin <max@puppetlabs.com>2011-04-21 19:04:04 -0700
committerMax Martin <max@puppetlabs.com>2011-04-21 19:04:04 -0700
commit1e9cc2cbf984633ab7ac63d466b3e4db8bca1445 (patch)
tree41991d2994934031c7e7671544d427f1d0a09257 /spec/unit
parente185be0a6d35c84a60b940f233f87c0908547dee (diff)
parent2a2226c0b71aafcda953057d3ecc8df5638447f2 (diff)
downloadpuppet-1e9cc2cbf984633ab7ac63d466b3e4db8bca1445.tar.gz
puppet-1e9cc2cbf984633ab7ac63d466b3e4db8bca1445.tar.xz
puppet-1e9cc2cbf984633ab7ac63d466b3e4db8bca1445.zip
Merge branch 'ticket/2.7.x/7080-reverts' into 2.7.x
* ticket/2.7.x/7080-reverts: Revert "Fixing Facts pson methods more resilient" Revert "(7080) Adding json support to Indirector Request" Revert "Adding json support to Puppet::Node"
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/indirector/request_spec.rb95
-rwxr-xr-xspec/unit/node/facts_spec.rb30
-rwxr-xr-xspec/unit/node_spec.rb63
3 files changed, 6 insertions, 182 deletions
diff --git a/spec/unit/indirector/request_spec.rb b/spec/unit/indirector/request_spec.rb
index ba7dc815e..87b9af438 100755
--- a/spec/unit/indirector/request_spec.rb
+++ b/spec/unit/indirector/request_spec.rb
@@ -301,99 +301,4 @@ describe Puppet::Indirector::Request do
lambda { @request.query_string }.should raise_error(ArgumentError)
end
end
-
- describe "when converting to json" do
- before do
- @request = Puppet::Indirector::Request.new(:facts, :find, "foo")
- end
-
- it "should produce a hash with the document_type set to 'request'" do
- @request.should set_json_document_type_to("Puppet::Indirector::Request")
- end
-
- it "should set the 'key'" do
- @request.should set_json_attribute("key").to("foo")
- end
-
- it "should include an attribute for its indirection name" do
- @request.should set_json_attribute("type").to("facts")
- end
-
- it "should include a 'method' attribute set to its method" do
- @request.should set_json_attribute("method").to("find")
- end
-
- it "should add all attributes under the 'attributes' attribute" do
- @request.ip = "127.0.0.1"
- @request.should set_json_attribute("attributes", "ip").to("127.0.0.1")
- end
-
- it "should add all options under the 'attributes' attribute" do
- @request.options["opt"] = "value"
- PSON.parse(@request.to_pson)["data"]['attributes']['opt'].should == "value"
- end
-
- it "should include the instance if provided" do
- facts = Puppet::Node::Facts.new("foo")
- @request.instance = facts
- PSON.parse(@request.to_pson)["data"]['instance'].should be_instance_of(Puppet::Node::Facts)
- end
- end
-
- describe "when converting from json" do
- before do
- @request = Puppet::Indirector::Request.new(:facts, :find, "foo")
- @klass = Puppet::Indirector::Request
- @format = Puppet::Network::FormatHandler.format('pson')
- end
-
- def from_json(json)
- @format.intern(Puppet::Indirector::Request, json)
- end
-
- it "should set the 'key'" do
- from_json(@request.to_pson).key.should == "foo"
- end
-
- it "should fail if no key is provided" do
- json = PSON.parse(@request.to_pson)
- json['data'].delete("key")
- lambda { from_json(json.to_pson) }.should raise_error(ArgumentError)
- end
-
- it "should set its indirector name" do
- from_json(@request.to_pson).indirection_name.should == :facts
- end
-
- it "should fail if no type is provided" do
- json = PSON.parse(@request.to_pson)
- json['data'].delete("type")
- lambda { from_json(json.to_pson) }.should raise_error(ArgumentError)
- end
-
- it "should set its method" do
- from_json(@request.to_pson).method.should == "find"
- end
-
- it "should fail if no method is provided" do
- json = PSON.parse(@request.to_pson)
- json['data'].delete("method")
- lambda { from_json(json.to_pson) }.should raise_error(ArgumentError)
- end
-
- it "should initialize with all attributes and options" do
- @request.ip = "127.0.0.1"
- @request.options["opt"] = "value"
- result = from_json(@request.to_pson)
- result.options[:opt].should == "value"
- result.ip.should == "127.0.0.1"
- end
-
- it "should set its instance as an instance if one is provided" do
- facts = Puppet::Node::Facts.new("foo")
- @request.instance = facts
- result = from_json(@request.to_pson)
- result.instance.should be_instance_of(Puppet::Node::Facts)
- end
- end
end
diff --git a/spec/unit/node/facts_spec.rb b/spec/unit/node/facts_spec.rb
index 1b6991ca0..efaa76e12 100755
--- a/spec/unit/node/facts_spec.rb
+++ b/spec/unit/node/facts_spec.rb
@@ -110,11 +110,7 @@ describe Puppet::Node::Facts, "when indirecting" do
end
it "should accept properly formatted pson" do
- 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"})
+ 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'
@@ -126,25 +122,11 @@ 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
- facts.to_pson.should == %Q[{"data":{"name":"foo","timestamp":"#{@timestamp}","expiration":"#{@expiration}","values":{"a":1,"b":2,"c":3}},"document_type":"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
+ result = PSON.parse(facts.to_pson)
+ result['name'].should == facts.name
+ result['values'].should == facts.values.reject { |key, value| key.to_s =~ /_/ }
+ result['timestamp'].should == facts.timestamp.to_s
+ result['expiration'].should == facts.expiration.to_s
end
end
end
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index e8f826dca..169a9cdcf 100755
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -36,69 +36,6 @@ 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
- @node.should set_json_attribute('name').to("mynode")
- end
-
- it "should include the classes if set" do
- @node.classes = %w{a b c}
- @node.should set_json_attribute("classes").to(%w{a b c})
- end
-
- it "should not include the classes if there are none" do
- @node.should_not set_json_attribute('classes')
- end
-
- it "should include parameters if set" do
- @node.parameters = {"a" => "b", "c" => "d"}
- @node.should set_json_attribute('parameters').to({"a" => "b", "c" => "d"})
- end
-
- it "should not include the parameters if there are none" do
- @node.should_not set_json_attribute('parameters')
- end
-
- it "should include the environment" do
- @node.environment = "production"
- @node.should set_json_attribute('environment').to('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
- Puppet::Node.should read_json_attribute('name').from(@node.to_pson).as("mynode")
- end
-
- it "should include the classes if set" do
- @node.classes = %w{a b c}
- Puppet::Node.should read_json_attribute('classes').from(@node.to_pson).as(%w{a b c})
- end
-
- it "should include parameters if set" do
- @node.parameters = {"a" => "b", "c" => "d"}
- Puppet::Node.should read_json_attribute('parameters').from(@node.to_pson).as({"a" => "b", "c" => "d"})
- end
-
- it "should include the environment" do
- @node.environment = "production"
- Puppet::Node.should read_json_attribute('environment').from(@node.to_pson).as(Puppet::Node::Environment.new(:production))
- end
- end
end
describe Puppet::Node, "when initializing" do