diff options
author | Jeremy J. Miller <jm@chef.io> | 2017-07-17 15:43:19 -0400 |
---|---|---|
committer | Jeremy J. Miller <jm@chef.io> | 2017-07-17 21:20:28 -0400 |
commit | 6b34164ae2783ae698802434e28c466c1a5b8754 (patch) | |
tree | ca8f6bcb2a03dd9ab61e99e3b581e6678ec5a656 | |
parent | 81fff868e720b519c39dacf8f09121416acbbff5 (diff) | |
download | chef-6b34164ae2783ae698802434e28c466c1a5b8754.tar.gz |
avoid mutation attempt of node['platform']
Fixes https://github.com/chef/chef/issues/6277
Added `node['platform']` and `node['platform_version']` attributes in
the unit tests to trigger a "can't modify frozen String" error.
Fixed by doing shallow copy of `node['platform']` on assignment.
Signed-off-by: Jeremy J. Miller <jm@chef.io>
-rw-r--r-- | lib/chef/knife/core/status_presenter.rb | 2 | ||||
-rw-r--r-- | spec/unit/knife/status_spec.rb | 2 |
2 files changed, 3 insertions, 1 deletions
diff --git a/lib/chef/knife/core/status_presenter.rb b/lib/chef/knife/core/status_presenter.rb index df6c2fe942..f55f9abcbb 100644 --- a/lib/chef/knife/core/status_presenter.rb +++ b/lib/chef/knife/core/status_presenter.rb @@ -123,7 +123,7 @@ class Chef line_parts << run_list if run_list if node["platform"] - platform = node["platform"] + platform = node["platform"].dup if node["platform_version"] platform << " #{node['platform_version']}" end diff --git a/spec/unit/knife/status_spec.rb b/spec/unit/knife/status_spec.rb index c87ea3ad17..929a0f742b 100644 --- a/spec/unit/knife/status_spec.rb +++ b/spec/unit/knife/status_spec.rb @@ -23,6 +23,8 @@ describe Chef::Knife::Status do node = Chef::Node.new.tap do |n| n.automatic_attrs["fqdn"] = "foobar" n.automatic_attrs["ohai_time"] = 1343845969 + n.automatic_attrs["platform"] = "mac_os_x" + n.automatic_attrs["platform_version"] = "10.12.5" end allow(Time).to receive(:now).and_return(Time.at(1428573420)) @query = double("Chef::Search::Query") |