summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarguerite <marguerite@pagerduty.com>2015-07-21 14:47:12 -0400
committermarguerite <marguerite@pagerduty.com>2015-07-21 15:35:58 -0400
commit577773bbb838a91fee53d1ad21dddfb5fd9dbd22 (patch)
treed41c35d6b3e35a786fd788914cc232f4abd2c31d
parent2c4d7c7cf40346ca8236054901c023f35e1300c9 (diff)
downloadchef-577773bbb838a91fee53d1ad21dddfb5fd9dbd22.tar.gz
Interpolate `%{path}` in verify command
See chef/chef#3232
-rw-r--r--lib/chef/resource/file/verification.rb4
-rw-r--r--spec/unit/resource/file/verification_spec.rb20
2 files changed, 18 insertions, 6 deletions
diff --git a/lib/chef/resource/file/verification.rb b/lib/chef/resource/file/verification.rb
index f1ca0f1883..6be1f912fd 100644
--- a/lib/chef/resource/file/verification.rb
+++ b/lib/chef/resource/file/verification.rb
@@ -106,7 +106,9 @@ 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.
+ 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..0ab4ce28e6 100644
--- a/spec/unit/resource/file/verification_spec.rb
+++ b/spec/unit/resource/file/verification_spec.rb
@@ -69,12 +69,22 @@ describe Chef::Resource::File::Verification do
end
context "with a verification command(String)" do
+ 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 "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