summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrajakta Purohit <prajakta@opscode.com>2014-02-04 08:46:02 -0800
committerPrajakta Purohit <prajakta@opscode.com>2014-02-04 10:20:03 -0800
commit17c83dc0376945bb67625e9f69e50fbe5036b8d3 (patch)
tree0d8aea27a3e874161a3f6d075ab34219c22b8bcc
parentf80d9ffe02ab89d56d1e94262b3168403eb210c4 (diff)
downloadchef-17c83dc0376945bb67625e9f69e50fbe5036b8d3.tar.gz
Adding tests to make sure the resource_name and resource_id are of type
String irrespective of input value type
-rw-r--r--spec/unit/resource_reporter_spec.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/unit/resource_reporter_spec.rb b/spec/unit/resource_reporter_spec.rb
index c6f41156a4..52fd44e692 100644
--- a/spec/unit/resource_reporter_spec.rb
+++ b/spec/unit/resource_reporter_spec.rb
@@ -262,6 +262,61 @@ describe Chef::ResourceReporter do
@resource_reporter.run_started(@run_status)
end
+ context "when the new_resource does not have a string for name and identity" do
+ context "the new_resource name and id are nil" do
+ before do
+ @bad_resource = Chef::Resource::File.new("/tmp/nameless_file.txt")
+ @bad_resource.stub(:name).and_return(nil)
+ @bad_resource.stub(:identity).and_return(nil)
+ @resource_reporter.resource_action_start(@bad_resource, :create)
+ @resource_reporter.resource_current_state_loaded(@bad_resource, :create, @current_resource)
+ @resource_reporter.resource_updated(@bad_resource, :create)
+ @resource_reporter.resource_completed(@bad_resource)
+ @run_status.stop_clock
+ @report = @resource_reporter.prepare_run_data
+ @first_update_report = @report["resources"].first
+ end
+
+ it "resource_name in prepared_run_data is a string" do
+ @first_update_report["name"].class.should == String
+ end
+
+ it "resource_id in prepared_run_data is a string" do
+ @first_update_report["id"].class.should == String
+ end
+ end
+
+ context "the new_resource name and id are hashes" do
+ before do
+ @bad_resource = Chef::Resource::File.new("/tmp/filename_as_hash.txt")
+ @bad_resource.stub(:name).and_return({:foo=>:bar})
+ @bad_resource.stub(:identity).and_return({:foo=>:bar})
+ @resource_reporter.resource_action_start(@bad_resource, :create)
+ @resource_reporter.resource_current_state_loaded(@bad_resource, :create, @current_resource)
+ @resource_reporter.resource_updated(@bad_resource, :create)
+ @resource_reporter.resource_completed(@bad_resource)
+ @run_status.stop_clock
+ @report = @resource_reporter.prepare_run_data
+ @first_update_report = @report["resources"].first
+ end
+ # Ruby 1.8.7 flattens out hash to string using join instead of inspect, resulting in
+ # irb(main):001:0> {:foo => :bar}.to_s
+ # => "foobar"
+ # instead of the expected
+ # irb(main):001:0> {:foo => :bar}.to_s
+ # => "{:foo=>:bar}"
+ # Hence checking for the class instead of the actual value.
+ it "resource_name in prepared_run_data is a string" do
+ @first_update_report["name"].class.should == String
+ end
+
+ it "resource_id in prepared_run_data is a string" do
+ @first_update_report["id"].class.should == String
+ end
+ end
+ end
+
+
context "for a successful client run" do
before do
# TODO: add inputs to generate expected output.