diff options
author | Adam Leff <adam@leff.co> | 2016-06-10 12:11:40 -0400 |
---|---|---|
committer | Adam Leff <adam@leff.co> | 2016-06-10 12:11:46 -0400 |
commit | 54ced0da2bd835e3753cbe51e588cf3e8040a6c9 (patch) | |
tree | 39b91829e643ae227693ae6666cc6abc738a8fe2 | |
parent | 8693be1d64b06b93fb357ac96588b17a6ea64579 (diff) | |
download | chef-adamleff/node-uuid-fix.tar.gz |
bug fix: correctly write out data collector metadata fileadamleff/node-uuid-fix
When we changed the messages from class instances to a module, the
reading of metadata into an instance variable was removed and
introduced a bug when updating metadata. This bug causes the
metadata to be properly read from disk, updated, but then the
metadata from disk is simply re-written to disk without the
intended updates.
-rw-r--r-- | lib/chef/data_collector/messages/helpers.rb | 4 | ||||
-rw-r--r-- | spec/unit/data_collector/messages/helpers_spec.rb | 10 |
2 files changed, 5 insertions, 9 deletions
diff --git a/lib/chef/data_collector/messages/helpers.rb b/lib/chef/data_collector/messages/helpers.rb index 3e52f80047..c0c700f847 100644 --- a/lib/chef/data_collector/messages/helpers.rb +++ b/lib/chef/data_collector/messages/helpers.rb @@ -148,8 +148,8 @@ class Chef end def update_metadata(key, value) - metadata[key] = value - Chef::FileCache.store(metadata_filename, metadata.to_json, 0644) + updated_metadata = metadata.tap { |x| x[key] = value } + Chef::FileCache.store(metadata_filename, updated_metadata.to_json, 0644) end def metadata_filename diff --git a/spec/unit/data_collector/messages/helpers_spec.rb b/spec/unit/data_collector/messages/helpers_spec.rb index 0ed0f6c921..26f7dbacfa 100644 --- a/spec/unit/data_collector/messages/helpers_spec.rb +++ b/spec/unit/data_collector/messages/helpers_spec.rb @@ -171,20 +171,16 @@ describe Chef::DataCollector::Messages::Helpers do end describe '#update_metadata' do - let(:metadata) { double("metadata") } - it "updates the file" do allow(TestMessage).to receive(:metadata_filename).and_return("fake_metadata_file.json") - allow(TestMessage).to receive(:metadata).and_return(metadata) - expect(metadata).to receive(:[]=).with("new_key", "new_value") - expect(metadata).to receive(:to_json).and_return("metadata_json") + allow(TestMessage).to receive(:metadata).and_return({ "key" => "current_value" }) expect(Chef::FileCache).to receive(:store).with( "fake_metadata_file.json", - "metadata_json", + '{"key":"updated_value"}', 0644 ) - TestMessage.update_metadata("new_key", "new_value") + TestMessage.update_metadata("key", "updated_value") end end end |