summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
authorScott Christopherson <scott@scott-christopherson.com>2017-01-20 10:56:48 -0500
committerScott Christopherson <scott@scott-christopherson.com>2017-01-20 11:01:24 -0500
commit1f514343a89f7ebc786422b66672c418f71e5093 (patch)
treed9e233794ddf651579ba0dfb7cf4c9e9e41f511e /spec/unit
parenta2e1d1d4edb74a968b416517fdbdf35740686467 (diff)
downloadchef-1f514343a89f7ebc786422b66672c418f71e5093.tar.gz
Do not modify File's new_resource during why-run
The `File` provider's `action_create` method would modify the `new_resource` object during a `why-run`. This was problematic when a `File` resource was configured with a `notifies :before` because resources with `before` timers have their actions executed twice. [Once](https://github.com/chef/chef/blob/a2e1d1d4edb74a968b416517fdbdf35740686467/lib/chef/runner.rb#L54-L57) in `why-run` mode to see if the other resources need to be notified, and then executed [once again](https://github.com/chef/chef/blob/a2e1d1d4edb74a968b416517fdbdf35740686467/lib/chef/runner.rb#L68-L69) after the `before` notifications are resolved. This behavior would result in existing File resources not getting their ownership and permissions updated properly during a converge. Signed-off-by: Scott Christopherson <scott@chef.io>
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/provider/directory_spec.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/spec/unit/provider/directory_spec.rb b/spec/unit/provider/directory_spec.rb
index aebbaa6e81..4672db7d8d 100644
--- a/spec/unit/provider/directory_spec.rb
+++ b/spec/unit/provider/directory_spec.rb
@@ -148,6 +148,16 @@ describe Chef::Provider::Directory do
directory.run_action(:create)
expect(new_resource).not_to be_updated
end
+
+ context "in why run mode" do
+ before { Chef::Config[:why_run] = true }
+ after { Chef::Config[:why_run] = false }
+
+ it "does not modify new_resource" do
+ expect(directory).not_to receive(:load_resource_attributes_from_file).with(new_resource)
+ directory.run_action(:create)
+ end
+ end
end
describe "when the directory does not exist" do