summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Duffield <tom@chef.io>2017-01-20 11:03:21 -0600
committerGitHub <noreply@github.com>2017-01-20 11:03:21 -0600
commitd4ef4471ee58f7d4c1a6ca2fca5de7e5f4736c1a (patch)
treed9e233794ddf651579ba0dfb7cf4c9e9e41f511e
parenta2e1d1d4edb74a968b416517fdbdf35740686467 (diff)
parent1f514343a89f7ebc786422b66672c418f71e5093 (diff)
downloadchef-d4ef4471ee58f7d4c1a6ca2fca5de7e5f4736c1a.tar.gz
Merge pull request #5742 from chef/COOL-615/before-notifies-fix
Do not modify File's new_resource during why-run
-rw-r--r--lib/chef/provider/directory.rb2
-rw-r--r--lib/chef/provider/file.rb2
-rw-r--r--spec/support/shared/unit/provider/file.rb10
-rw-r--r--spec/unit/provider/directory_spec.rb10
4 files changed, 22 insertions, 2 deletions
diff --git a/lib/chef/provider/directory.rb b/lib/chef/provider/directory.rb
index 619ab5d8b6..1cacc3fcb9 100644
--- a/lib/chef/provider/directory.rb
+++ b/lib/chef/provider/directory.rb
@@ -138,7 +138,7 @@ class Chef
end
do_acl_changes
do_selinux(true)
- load_resource_attributes_from_file(@new_resource)
+ load_resource_attributes_from_file(@new_resource) unless Chef::Config[:why_run]
end
def action_delete
diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb
index 84bb4d1c94..f77986fa03 100644
--- a/lib/chef/provider/file.rb
+++ b/lib/chef/provider/file.rb
@@ -154,7 +154,7 @@ class Chef
do_contents_changes
do_acl_changes
do_selinux
- load_resource_attributes_from_file(@new_resource)
+ load_resource_attributes_from_file(@new_resource) unless Chef::Config[:why_run]
end
def action_create_if_missing
diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb
index 394fdaa02f..b58159fcc9 100644
--- a/spec/support/shared/unit/provider/file.rb
+++ b/spec/support/shared/unit/provider/file.rb
@@ -683,6 +683,16 @@ shared_examples_for Chef::Provider::File do
end
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
+ setup_missing_file
+ expect(provider).not_to receive(:load_resource_attributes_from_file).with(provider.new_resource)
+ provider.run_action(:create)
+ end
+ end
end
context "action delete" do
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