summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorAdam Leff <adam@leff.co>2016-06-07 15:39:06 -0400
committerAdam Leff <adam@leff.co>2016-06-07 15:39:06 -0400
commitc4cf0bbf1836fb70b0dc3aaf2f5df0399f5633ee (patch)
treeee4f8e435ed1985c7d0bd289ede6d23a23723cfb /spec
parentea15504eb0e8797a435eb8c823e31bdb996a4305 (diff)
downloadchef-c4cf0bbf1836fb70b0dc3aaf2f5df0399f5633ee.tar.gz
Bug fix: updated_resource_count should only include updated resources
After adding up-to-date and skipped resources to the DataCollector resource list, the logic that computed the number of resources updated needed to change accordingly. This change fixes that bug and also eliminates an unnecessary counter that tracks the total number of resources.
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/data_collector/messages_spec.rb13
-rw-r--r--spec/unit/data_collector_spec.rb31
2 files changed, 14 insertions, 30 deletions
diff --git a/spec/unit/data_collector/messages_spec.rb b/spec/unit/data_collector/messages_spec.rb
index aacca6444d..dee86a3907 100644
--- a/spec/unit/data_collector/messages_spec.rb
+++ b/spec/unit/data_collector/messages_spec.rb
@@ -61,12 +61,13 @@ describe Chef::DataCollector::Messages do
end
describe '#run_end_message' do
- let(:run_status) { Chef::RunStatus.new(Chef::Node.new, Chef::EventDispatch::Dispatcher.new) }
- let(:resource) { double("resource", for_json: "resource_data") }
+ let(:run_status) { Chef::RunStatus.new(Chef::Node.new, Chef::EventDispatch::Dispatcher.new) }
+ let(:resource1) { double("resource1", for_json: "resource_data", status: "updated") }
+ let(:resource2) { double("resource2", for_json: "resource_data", status: "skipped") }
let(:reporter_data) do
{
run_status: run_status,
- updated_resources: [resource],
+ completed_resources: [resource1, resource2],
}
end
@@ -116,6 +117,12 @@ describe Chef::DataCollector::Messages do
end
expect(extra_fields).to eq([])
end
+
+ it "only includes updated resources in its count" do
+ message = Chef::DataCollector::Messages.run_end_message(reporter_data)
+ expect(message["total_resource_count"]).to eq(2)
+ expect(message["updated_resource_count"]).to eq(1)
+ end
end
context "when the run was not successful" do
diff --git a/spec/unit/data_collector_spec.rb b/spec/unit/data_collector_spec.rb
index 6065cbc8b1..78b0aaf97d 100644
--- a/spec/unit/data_collector_spec.rb
+++ b/spec/unit/data_collector_spec.rb
@@ -226,17 +226,11 @@ describe Chef::DataCollector::Reporter do
let(:resource_report) { double("resource_report") }
before do
- allow(reporter).to receive(:increment_resource_count)
allow(reporter).to receive(:nested_resource?)
allow(reporter).to receive(:current_resource_report).and_return(resource_report)
allow(resource_report).to receive(:up_to_date)
end
- it "increments the resource count" do
- expect(reporter).to receive(:increment_resource_count)
- reporter.resource_up_to_date(new_resource, action)
- end
-
context "when the resource is a nested resource" do
it "does not mark the resource report as up-to-date" do
allow(reporter).to receive(:nested_resource?).with(new_resource).and_return(true)
@@ -261,17 +255,11 @@ describe Chef::DataCollector::Reporter do
let(:resource_report) { double("resource_report") }
before do
- allow(reporter).to receive(:increment_resource_count)
allow(reporter).to receive(:nested_resource?)
allow(reporter).to receive(:current_resource_report).and_return(resource_report)
allow(resource_report).to receive(:skipped)
end
- it "increments the resource count" do
- expect(reporter).to receive(:increment_resource_count)
- reporter.resource_skipped(new_resource, action, conditional)
- end
-
context "when the resource is a nested resource" do
it "does not mark the resource report as skipped" do
allow(reporter).to receive(:nested_resource?).with(new_resource).and_return(true)
@@ -307,11 +295,6 @@ describe Chef::DataCollector::Reporter do
allow(resource_report).to receive(:updated)
end
- it "increments the resource count" do
- expect(reporter).to receive(:increment_resource_count)
- reporter.resource_updated("new_resource", "action")
- end
-
it "marks the resource report as updated" do
expect(resource_report).to receive(:updated)
reporter.resource_updated("new_resource", "action")
@@ -326,7 +309,6 @@ describe Chef::DataCollector::Reporter do
let(:resource_report) { double("resource_report") }
before do
- allow(reporter).to receive(:increment_resource_count)
allow(reporter).to receive(:update_error_description)
allow(reporter).to receive(:current_resource_report).and_return(resource_report)
allow(resource_report).to receive(:failed)
@@ -334,11 +316,6 @@ describe Chef::DataCollector::Reporter do
allow(error_mapper).to receive(:for_json)
end
- it "increments the resource count" do
- expect(reporter).to receive(:increment_resource_count)
- reporter.resource_failed(new_resource, action, exception)
- end
-
it "updates the error description" do
expect(Chef::Formatters::ErrorMapper).to receive(:resource_failed).with(
new_resource,
@@ -372,7 +349,7 @@ describe Chef::DataCollector::Reporter do
let(:resource_report) { double("resource_report") }
before do
- allow(reporter).to receive(:add_updated_resource)
+ allow(reporter).to receive(:add_completed_resource)
allow(reporter).to receive(:update_current_resource_report)
allow(resource_report).to receive(:finish)
end
@@ -380,7 +357,7 @@ describe Chef::DataCollector::Reporter do
context "when there is no current resource report" do
it "does not add the updated resource" do
allow(reporter).to receive(:current_resource_report).and_return(nil)
- expect(reporter).not_to receive(:add_updated_resource)
+ expect(reporter).not_to receive(:add_completed_resource)
reporter.resource_completed(new_resource)
end
end
@@ -393,7 +370,7 @@ describe Chef::DataCollector::Reporter do
context "when the resource is a nested resource" do
it "does not add the updated resource" do
allow(reporter).to receive(:nested_resource?).with(new_resource).and_return(true)
- expect(reporter).not_to receive(:add_updated_resource)
+ expect(reporter).not_to receive(:add_completed_resource)
reporter.resource_completed(new_resource)
end
end
@@ -409,7 +386,7 @@ describe Chef::DataCollector::Reporter do
end
it "adds the resource to the updated resource list" do
- expect(reporter).to receive(:add_updated_resource).with(resource_report)
+ expect(reporter).to receive(:add_completed_resource).with(resource_report)
reporter.resource_completed(new_resource)
end