diff options
author | sersut <serdar@opscode.com> | 2014-01-17 15:39:15 -0800 |
---|---|---|
committer | sersut <serdar@opscode.com> | 2014-01-17 15:39:15 -0800 |
commit | 65aa6df892b98b5f78ea81ed7eb0bc8f797fc73a (patch) | |
tree | 8bc74c5106689cef1817ea8f331d013f93b4a825 | |
parent | 330a650a9070e68264a18a296a0995150a9b10e7 (diff) | |
download | chef-65aa6df892b98b5f78ea81ed7eb0bc8f797fc73a.tar.gz |
Restore checksums in the output.
-rw-r--r-- | lib/chef/provider/file.rb | 22 | ||||
-rw-r--r-- | spec/support/shared/functional/file_resource.rb | 32 |
2 files changed, 31 insertions, 23 deletions
diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb index 9a3e038e19..3ef7725173 100644 --- a/lib/chef/provider/file.rb +++ b/lib/chef/provider/file.rb @@ -355,24 +355,21 @@ class Chef # the file? on the next line suppresses the case in why-run when we have a not-file here that would have otherwise been removed if ::File.file?(@new_resource.path) && contents_changed? - if @new_resource.sensitive - @new_resource.diff('suppressed sensitive resource') + description = [ "update content in file #{@new_resource.path} from \ +#{short_cksum(@current_resource.checksum)} to #{short_cksum(checksum(tempfile.path))}" ] - converge_by(['suppressed sensitive resource']) do - update_file_contents - end + # Hide the diff output if the resource is marked as a sensitive resource + if @new_resource.sensitive + @new_resource.diff("suppressed sensitive resource") + description << "suppressed sensitive resource" else diff.diff(@current_resource.path, tempfile.path) - @new_resource.diff( diff.for_reporting ) unless file_created? - - description = [ "update content in file #{@new_resource.path} from #{short_cksum(@current_resource.checksum)} to #{short_cksum(checksum(tempfile.path))}" ] - description << diff.for_output + end - converge_by(description) do - update_file_contents - end + converge_by(description) do + update_file_contents end end @@ -434,4 +431,3 @@ class Chef end end end - diff --git a/spec/support/shared/functional/file_resource.rb b/spec/support/shared/functional/file_resource.rb index 25fbd171c8..ba06235aa8 100644 --- a/spec/support/shared/functional/file_resource.rb +++ b/spec/support/shared/functional/file_resource.rb @@ -16,6 +16,8 @@ # limitations under the License. # +require 'pry' + shared_context "deploying with move" do before do Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH @@ -133,25 +135,35 @@ shared_examples_for "a file with the wrong content" do end - context "`.diff`'s enabled" do - describe '.sensitive' do - context "`.sensitive`'s insensitive by default" do + context "when diff is enabled" do + describe 'sensitive attribute' do + context "should be insensitive by default" do it { expect(resource.sensitive).to(be_false) } end - context "`.sensitive`'s sensitive" do + context "when set" do before { resource.sensitive(true) } - it { expect(resource.sensitive).to(be_true) } + it "should be set on the resource" do + expect(resource.sensitive).to(be_true) + end - context '`.sensitive` suppresses a sensitive resource' do - subject(:provider) { resource.provider_for_action(:create) } + context "when running :create action" do + let(:provider) { resource.provider_for_action(:create) } + let(:reporter_messages) { provider.instance_variable_get("@converge_actions").actions[0][0] } - before { provider.run_action } + before do + provider.run_action + end - it { expect(resource.diff).to(include('suppressed sensitive resource')) } + it "should suppress the diff" do + expect(resource.diff).to(include('suppressed sensitive resource')) + expect(reporter_messages[1]).to eq("suppressed sensitive resource") + end - it { expect(provider.instance_variable_get("@converge_actions").actions[0][0]).to(eq(['suppressed sensitive resource'])) } + it "should still include the updated checksums" do + expect(reporter_messages[0]).to include("update content in file") + end end end end |