summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@chef.io>2016-11-03 20:50:13 -0700
committerdanielsdeleo <dan@chef.io>2016-11-03 21:20:50 -0700
commita88e3068a9bd1755120663c8a4ff6ced70c7fd1d (patch)
treecbeb1e40c9339f30d8833ec25c76d2cd9a1d8755
parenta155e20e796e16902498634efe9798b135395d9a (diff)
downloadchef-a88e3068a9bd1755120663c8a4ff6ced70c7fd1d.tar.gz
Don't double-JSON data collector run complete messages
Signed-off-by: Daniel DeLeo <dan@chef.io>
-rw-r--r--lib/chef/data_collector.rb2
-rw-r--r--spec/unit/data_collector_spec.rb48
2 files changed, 39 insertions, 11 deletions
diff --git a/lib/chef/data_collector.rb b/lib/chef/data_collector.rb
index b92e9c122f..da7aeee3b8 100644
--- a/lib/chef/data_collector.rb
+++ b/lib/chef/data_collector.rb
@@ -359,7 +359,7 @@ class Chef
status: opts[:status],
error_descriptions: error_descriptions,
deprecations: deprecations.to_a
- ).to_json
+ )
)
end
diff --git a/spec/unit/data_collector_spec.rb b/spec/unit/data_collector_spec.rb
index fceea3225f..b3e2d931a7 100644
--- a/spec/unit/data_collector_spec.rb
+++ b/spec/unit/data_collector_spec.rb
@@ -291,19 +291,47 @@ describe Chef::DataCollector::Reporter do
end
end
- describe "#run_completed" do
- it "sends the run completion" do
- node = Chef::Node.new
+ describe "when sending a message at chef run completion" do
- expect(reporter).to receive(:send_run_completion).with(status: "success")
- reporter.run_completed(node)
+ let(:node) { Chef::Node.new }
+
+ let(:run_status) do
+ instance_double("Chef::RunStatus",
+ run_id: "run_id",
+ node: node,
+ start_time: Time.new,
+ end_time: Time.new,
+ exception: exception)
end
- end
- describe "#run_failed" do
- it "updates the exception and sends the run completion" do
- expect(reporter).to receive(:send_run_completion).with(status: "failure")
- reporter.run_failed("test_exception")
+ before do
+ reporter.send(:update_run_status, run_status)
+ end
+
+ describe "#run_completed" do
+
+ let(:exception) { nil }
+
+ it "sends the run completion" do
+ expect(reporter).to receive(:send_to_data_collector) do |message|
+ expect(message).to be_a(Hash)
+ expect(message["status"]).to eq("success")
+ end
+ reporter.run_completed(node)
+ end
+ end
+
+ describe "#run_failed" do
+
+ let(:exception) { StandardError.new("oops") }
+
+ it "updates the exception and sends the run completion" do
+ expect(reporter).to receive(:send_to_data_collector) do |message|
+ expect(message).to be_a(Hash)
+ expect(message["status"]).to eq("failure")
+ end
+ reporter.run_failed("test_exception")
+ end
end
end