diff options
author | Adam Leff <adam@leff.co> | 2016-06-28 17:02:37 -0400 |
---|---|---|
committer | Adam Leff <adam@leff.co> | 2016-06-28 17:19:54 -0400 |
commit | 5137634af0777d8a49b0347b08eddd6aae0ecec7 (patch) | |
tree | 84ebf5498a5c6dce48b73e24667b28c917577f6b /spec/unit/data_collector | |
parent | 3f6db5dc96b5ecb552a491e77730356e8df2021d (diff) | |
download | chef-5137634af0777d8a49b0347b08eddd6aae0ecec7.tar.gz |
ensuring the node in the run_converge message is a node object and that it gets serialized correctlyadamleff/include-node-in-converge-messages
Diffstat (limited to 'spec/unit/data_collector')
-rw-r--r-- | spec/unit/data_collector/messages_spec.rb | 18 |
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{ |