summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2016-11-04 12:05:25 -0400
committerGitHub <noreply@github.com>2016-11-04 12:05:25 -0400
commita4a95c8254ee4c80d5339ee3a81745a5c581dc7c (patch)
treeba47132b86549b3e8d8c5263d2009ce6c7802b98
parenta155e20e796e16902498634efe9798b135395d9a (diff)
parentf3a2fbda250418cbe1c94ad73a45e77eb1a24c38 (diff)
downloadchef-a4a95c8254ee4c80d5339ee3a81745a5c581dc7c.tar.gz
Merge pull request #5514 from chef/fix-data-collector-acceptance
Fix data collector acceptance
-rw-r--r--acceptance/data-collector/test/integration/default/serverspec/default_spec.rb14
-rw-r--r--lib/chef/data_collector.rb2
-rw-r--r--spec/unit/data_collector_spec.rb48
3 files changed, 42 insertions, 22 deletions
diff --git a/acceptance/data-collector/test/integration/default/serverspec/default_spec.rb b/acceptance/data-collector/test/integration/default/serverspec/default_spec.rb
index f9d365ac58..59c1f8d21b 100644
--- a/acceptance/data-collector/test/integration/default/serverspec/default_spec.rb
+++ b/acceptance/data-collector/test/integration/default/serverspec/default_spec.rb
@@ -60,7 +60,7 @@ end
shared_examples_for "counter checks" do |counters_to_check|
counters_to_check.each do |counter, value|
- it "counter #{counter} should equal #{value}" do
+ it "counter #{counter} should equal #{value.inspect}" do
counter_values = JSON.load(command("curl http://localhost:9292/counters").stdout)
expect(counter_values[counter]).to eq(value)
end
@@ -91,11 +91,6 @@ shared_examples_for "run_start payload check" do
expect(missing_fields).to eq([])
end
- it "does not have any extra fields" do
- payload = JSON.load(command("curl http://localhost:9292/cache/run_start").stdout)
- extra_fields = payload.keys.select { |key| !required_fields.include?(key) && !optional_fields.include?(key) }
- expect(extra_fields).to eq([])
- end
end
end
@@ -121,6 +116,7 @@ shared_examples_for "run_converge.success payload check" do
status
total_resource_count
updated_resource_count
+ deprecations
}
end
let(:optional_fields) { [] }
@@ -131,11 +127,6 @@ shared_examples_for "run_converge.success payload check" do
expect(missing_fields).to eq([])
end
- it "does not have any extra fields" do
- payload = JSON.load(command("curl http://localhost:9292/cache/run_converge.success").stdout)
- extra_fields = payload.keys.select { |key| !required_fields.include?(key) && !optional_fields.include?(key) }
- expect(extra_fields).to eq([])
- end
end
end
@@ -162,6 +153,7 @@ shared_examples_for "run_converge.failure payload check" do
status
total_resource_count
updated_resource_count
+ deprecations
}
end
let(:optional_fields) { [] }
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