diff options
author | marguerite <marguerite@pagerduty.com> | 2015-07-21 15:36:21 -0400 |
---|---|---|
committer | marguerite <marguerite@pagerduty.com> | 2015-07-22 09:40:29 -0400 |
commit | e330c30a6d9db16cc65f16164a40cfc96c0f6f7a (patch) | |
tree | 37d3dc91365b39683fc9fb88d9a77b8026991df1 | |
parent | 577773bbb838a91fee53d1ad21dddfb5fd9dbd22 (diff) | |
download | chef-e330c30a6d9db16cc65f16164a40cfc96c0f6f7a.tar.gz |
Warn about deprecation `%{file}` interpolation in verify command
See chef/chef#3232
-rw-r--r-- | lib/chef/resource/file/verification.rb | 4 | ||||
-rw-r--r-- | spec/unit/resource/file/verification_spec.rb | 18 |
2 files changed, 22 insertions, 0 deletions
diff --git a/lib/chef/resource/file/verification.rb b/lib/chef/resource/file/verification.rb index 6be1f912fd..faf4791884 100644 --- a/lib/chef/resource/file/verification.rb +++ b/lib/chef/resource/file/verification.rb @@ -108,6 +108,10 @@ class Chef def verify_command(path, opts) # First implementation interpolated `file`; docs & RFC claim `path` # is interpolated. Until `file` can be deprecated, interpolate both. + Chef::Log.deprecation( + '%{file} is deprecated in verify command and will not be '\ + 'supported in Chef 13. Please use %{path} instead.' + ) if @command.include?('%{file}') command = @command % {:file => path, :path => path} interpreter = Chef::GuardInterpreter.for_resource(@parent_resource, command, @command_opts) interpreter.evaluate diff --git a/spec/unit/resource/file/verification_spec.rb b/spec/unit/resource/file/verification_spec.rb index 0ab4ce28e6..04ae9ad629 100644 --- a/spec/unit/resource/file/verification_spec.rb +++ b/spec/unit/resource/file/verification_spec.rb @@ -69,6 +69,10 @@ describe Chef::Resource::File::Verification do end context "with a verification command(String)" do + before(:each) do + allow(Chef::Log).to receive(:deprecation).and_return(nil) + end + def platform_specific_verify_command(variable_name) if windows? "if \"#{temp_path}\" == \"%{#{variable_name}}\" (exit 0) else (exit 1)" @@ -83,6 +87,20 @@ describe Chef::Resource::File::Verification do expect(v.verify(temp_path)).to eq(true) end + it "warns about deprecation when \%{file} is used" do + expect(Chef::Log).to receive(:deprecation).with(/%{file} is deprecated/) + test_command = platform_specific_verify_command('file') + Chef::Resource::File::Verification.new(parent_resource, test_command, {}) + .verify(temp_path) + end + + it "does not warn about deprecation when \%{file} is not used" do + expect(Chef::Log).to_not receive(:deprecation) + test_command = platform_specific_verify_command('path') + Chef::Resource::File::Verification.new(parent_resource, test_command, {}) + .verify(temp_path) + end + it "substitutes \%{path} with the path" do test_command = platform_specific_verify_command('path') v = Chef::Resource::File::Verification.new(parent_resource, test_command, {}) |