diff options
author | Adam Leff <adam@leff.co> | 2016-11-21 22:01:50 -0500 |
---|---|---|
committer | Adam Leff <adam@leff.co> | 2016-11-21 22:07:41 -0500 |
commit | 091df73931ecff79927ab9b55c0f284024c6a58e (patch) | |
tree | 5cff4bf2e8188f5d0c0a6d0e069baabf0179c533 /spec/unit/data_collector_spec.rb | |
parent | b488d5ba2afec65939cb4a267151fd26a21b3d1a (diff) | |
download | chef-091df73931ecff79927ab9b55c0f284024c6a58e.tar.gz |
Ensure Data Collector resource report exists before updatingadamleff/fix-data-collector
In certain cases when using custom resources, we have seen evidence
of resource_updated and resource_failed events getting fired before
the DataCollector instance has a valid resource report created to
track such updates/failures.
This change ensures a resource report exists before attempting to
modify it, regardless of what order these events may fire.
Signed-off-by: Adam Leff <adam@leff.co>
Diffstat (limited to 'spec/unit/data_collector_spec.rb')
-rw-r--r-- | spec/unit/data_collector_spec.rb | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/spec/unit/data_collector_spec.rb b/spec/unit/data_collector_spec.rb index b3e2d931a7..4ae227ba3c 100644 --- a/spec/unit/data_collector_spec.rb +++ b/spec/unit/data_collector_spec.rb @@ -371,12 +371,10 @@ describe Chef::DataCollector::Reporter do end context "when resource is not a nested resource" do - it "creates the resource report and stores it as the current one" do + it "initializes the resource report" do allow(reporter).to receive(:nested_resource?).and_return(false) - expect(reporter).to receive(:create_resource_report) + expect(reporter).to receive(:initialize_resource_report_if_needed) .with(new_resource, action, current_resource) - .and_return(resource_report) - expect(reporter).to receive(:update_current_resource_report).with(resource_report) reporter.resource_current_state_loaded(new_resource, action, current_resource) end end @@ -418,7 +416,6 @@ describe Chef::DataCollector::Reporter do before do allow(reporter).to receive(:nested_resource?) - allow(reporter).to receive(:create_resource_report).and_return(resource_report) allow(resource_report).to receive(:skipped) end @@ -431,17 +428,10 @@ describe Chef::DataCollector::Reporter do end context "when the resource is not a nested resource" do - it "creates the resource report and stores it as the current one" do + it "initializes the resource report and marks it as skipped" do allow(reporter).to receive(:nested_resource?).and_return(false) - expect(reporter).to receive(:create_resource_report) - .with(new_resource, action) - .and_return(resource_report) - expect(reporter).to receive(:update_current_resource_report).with(resource_report) - reporter.resource_skipped(new_resource, action, conditional) - end - - it "marks the resource report as skipped" do - allow(reporter).to receive(:nested_resource?).with(new_resource).and_return(false) + allow(reporter).to receive(:current_resource_report).and_return(resource_report) + expect(reporter).to receive(:initialize_resource_report_if_needed).with(new_resource, action) expect(resource_report).to receive(:skipped).with(conditional) reporter.resource_skipped(new_resource, action, conditional) end @@ -548,7 +538,7 @@ describe Chef::DataCollector::Reporter do end it "nils out the current resource report" do - expect(reporter).to receive(:update_current_resource_report).with(nil) + expect(reporter).to receive(:clear_current_resource_report) reporter.resource_completed(new_resource) end end |