summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2015-07-23 09:37:34 +0100
committerThom May <thom@may.lt>2015-07-23 09:37:34 +0100
commit5daf096d9e97a8b7de9af805b7f5a1f38ff5b0ba (patch)
tree37d3dc91365b39683fc9fb88d9a77b8026991df1
parent2c4d7c7cf40346ca8236054901c023f35e1300c9 (diff)
parente330c30a6d9db16cc65f16164a40cfc96c0f6f7a (diff)
downloadchef-5daf096d9e97a8b7de9af805b7f5a1f38ff5b0ba.tar.gz
Merge pull request #3693 from margueritepd/issue-3232-template-verify-to-use-path-as-variable
Interpolate `%{path}` in verify command
-rw-r--r--lib/chef/resource/file/verification.rb8
-rw-r--r--spec/unit/resource/file/verification_spec.rb38
2 files changed, 40 insertions, 6 deletions
diff --git a/lib/chef/resource/file/verification.rb b/lib/chef/resource/file/verification.rb
index f1ca0f1883..faf4791884 100644
--- a/lib/chef/resource/file/verification.rb
+++ b/lib/chef/resource/file/verification.rb
@@ -106,7 +106,13 @@ class Chef
# We reuse Chef::GuardInterpreter in order to support
# the same set of options that the not_if/only_if blocks do
def verify_command(path, opts)
- command = @command % {:file => path}
+ # 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
end
diff --git a/spec/unit/resource/file/verification_spec.rb b/spec/unit/resource/file/verification_spec.rb
index 3609d9d482..04ae9ad629 100644
--- a/spec/unit/resource/file/verification_spec.rb
+++ b/spec/unit/resource/file/verification_spec.rb
@@ -69,12 +69,40 @@ 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)"
+ else
+ "test #{temp_path} = %{#{variable_name}}"
+ end
+ end
+
it "substitutes \%{file} with the path" do
- test_command = if windows?
- "if \"#{temp_path}\" == \"%{file}\" (exit 0) else (exit 1)"
- else
- "test #{temp_path} = %{file}"
- end
+ test_command = platform_specific_verify_command('file')
+ v = Chef::Resource::File::Verification.new(parent_resource, test_command, {})
+ 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, {})
expect(v.verify(temp_path)).to eq(true)
end