summaryrefslogtreecommitdiff
path: root/spec/unit/data_collector
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/data_collector')
-rw-r--r--spec/unit/data_collector/messages_spec.rb18
1 files changed, 17 insertions, 1 deletions
diff --git a/spec/unit/data_collector/messages_spec.rb b/spec/unit/data_collector/messages_spec.rb
index 24d225a1fe..b0c7e692d2 100644
--- a/spec/unit/data_collector/messages_spec.rb
+++ b/spec/unit/data_collector/messages_spec.rb
@@ -18,6 +18,7 @@
#
require "spec_helper"
+require "ffi_yajl"
require "chef/data_collector/messages/helpers"
describe Chef::DataCollector::Messages do
@@ -61,7 +62,8 @@ 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(:node) { Chef::Node.new }
+ let(:run_status) { Chef::RunStatus.new(node, Chef::EventDispatch::Dispatcher.new) }
let(:report1) { double("report1", report_data: { "status" => "updated" }) }
let(:report2) { double("report2", report_data: { "status" => "skipped" }) }
let(:reporter_data) do
@@ -76,6 +78,20 @@ describe Chef::DataCollector::Messages do
allow(run_status).to receive(:end_time).and_return(Time.now)
end
+ it "includes a valid node object in the payload" do
+ message = Chef::DataCollector::Messages.run_end_message(reporter_data)
+ expect(message["node"]).to be_an_instance_of(Chef::Node)
+ end
+
+ it "returns a sane JSON representation of the node object" do
+ node.chef_environment = "my_test_environment"
+ node.run_list.add("recipe[my_test_cookbook::default]")
+ message = FFI_Yajl::Parser.parse(Chef::DataCollector::Messages.run_end_message(reporter_data).to_json)
+
+ expect(message["node"]["chef_environment"]).to eq("my_test_environment")
+ expect(message["node"]["run_list"]).to eq(["recipe[my_test_cookbook::default]"])
+ end
+
context "when the run was successful" do
let(:required_fields) do
%w{