diff options
author | Adam Leff <adam@leff.co> | 2016-12-07 11:15:18 -0500 |
---|---|---|
committer | Adam Leff <adam@leff.co> | 2016-12-07 11:15:50 -0500 |
commit | 4a339b4dc83a535bd1e56a69e36c2bb2afe1086b (patch) | |
tree | de08e805b810016808a7f5979c7ddd55f95da8fc | |
parent | 31ded71e8c00e2a26cf0cdfee42f56998f03dcbc (diff) | |
download | chef-4a339b4dc83a535bd1e56a69e36c2bb2afe1086b.tar.gz |
adding test for when a resource overrides #hashadamleff/fix-data-collector-set
Signed-off-by: Adam Leff <adam@leff.co>
-rw-r--r-- | spec/unit/data_collector_spec.rb | 65 |
1 files changed, 47 insertions, 18 deletions
diff --git a/spec/unit/data_collector_spec.rb b/spec/unit/data_collector_spec.rb index 18a778b714..f3f7ffb30f 100644 --- a/spec/unit/data_collector_spec.rb +++ b/spec/unit/data_collector_spec.rb @@ -684,29 +684,58 @@ describe Chef::DataCollector::Reporter do end describe "#detect_unprocessed_resources" do - it "adds resource reports for any resources that have not yet been processed" do - resource_a = Chef::Resource::Service.new("processed service") - resource_b = Chef::Resource::Service.new("unprocessed service") + context "when resources do not override core methods" do + it "adds resource reports for any resources that have not yet been processed" do + resource_a = Chef::Resource::Service.new("processed service") + resource_b = Chef::Resource::Service.new("unprocessed service") - resource_a.action = [ :enable, :start ] - resource_b.action = :start + resource_a.action = [ :enable, :start ] + resource_b.action = :start - run_context = Chef::RunContext.new(Chef::Node.new, Chef::CookbookCollection.new, nil) - run_context.resource_collection.insert(resource_a) - run_context.resource_collection.insert(resource_b) + run_context = Chef::RunContext.new(Chef::Node.new, Chef::CookbookCollection.new, nil) + run_context.resource_collection.insert(resource_a) + run_context.resource_collection.insert(resource_b) - allow(reporter).to receive(:run_context).and_return(run_context) + allow(reporter).to receive(:run_context).and_return(run_context) - # process the actions for resource_a, but not resource_b - reporter.resource_up_to_date(resource_a, :enable) - reporter.resource_completed(resource_a) - reporter.resource_up_to_date(resource_a, :start) - reporter.resource_completed(resource_a) - expect(reporter.all_resource_reports.size).to eq(2) + # process the actions for resource_a, but not resource_b + reporter.resource_up_to_date(resource_a, :enable) + reporter.resource_completed(resource_a) + reporter.resource_up_to_date(resource_a, :start) + reporter.resource_completed(resource_a) + expect(reporter.all_resource_reports.size).to eq(2) - # detect unprocessed resourced, which should find that resource_b has not yet been processed - reporter.send(:detect_unprocessed_resources) - expect(reporter.all_resource_reports.size).to eq(3) + # detect unprocessed resources, which should find that resource_b has not yet been processed + reporter.send(:detect_unprocessed_resources) + expect(reporter.all_resource_reports.size).to eq(3) + end + end + + context "when a resource overrides a core method, such as #hash" do + it "does not raise an exception" do + resource_a = Chef::Resource::Service.new("processed service") + resource_b = Chef::Resource::Service.new("unprocessed service") + + resource_a.action = :start + resource_b.action = :start + + run_context = Chef::RunContext.new(Chef::Node.new, Chef::CookbookCollection.new, nil) + run_context.resource_collection.insert(resource_a) + run_context.resource_collection.insert(resource_b) + + allow(reporter).to receive(:run_context).and_return(run_context) + + # override the #hash method on resource_a to return a String instead of + # a Fixnum. Without the fix in chef/chef#5604, this would raise an + # exception when getting added to the Set/Hash. + resource_a.define_singleton_method(:hash) { "a string" } + + # process the actions for resource_a, but not resource_b + reporter.resource_up_to_date(resource_a, :start) + reporter.resource_completed(resource_a) + + expect { reporter.send(:detect_unprocessed_resources) }.not_to raise_error + end end end end |