summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-07-23 10:37:52 -0700
committerGitHub <noreply@github.com>2018-07-23 10:37:52 -0700
commit78a46b3e0734121e4c63731083c0dd323ae4c7b7 (patch)
treeda4f82a2dd6a13e17c0fee884372da4f1009a518
parent2d04dd17b58beef022543df55b886f54c17f718d (diff)
parent4189607688d98044f5b382b577b0a2db24732005 (diff)
downloadchef-78a46b3e0734121e4c63731083c0dd323ae4c7b7.tar.gz
Merge pull request #7341 from josh-barker/chef-13
Check local file exists before installing a windows package
-rw-r--r--lib/chef/provider/package/windows.rb8
-rw-r--r--spec/unit/provider/package/windows_spec.rb19
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/chef/provider/package/windows.rb b/lib/chef/provider/package/windows.rb
index bade7f27a3..1d160095be 100644
--- a/lib/chef/provider/package/windows.rb
+++ b/lib/chef/provider/package/windows.rb
@@ -39,6 +39,14 @@ class Chef
a.assertion { new_resource.source || msi? }
a.failure_message Chef::Exceptions::NoWindowsPackageSource, "Source for package #{new_resource.name} must be specified in the resource's source property for package to be installed because the package_name property is used to test for the package installation state for this package type."
end
+
+ unless uri_scheme?(new_resource.source)
+ requirements.assert(:install) do |a|
+ a.assertion { ::File.exist?(new_resource.source) }
+ a.failure_message Chef::Exceptions::Package, "Source for package #{new_resource.name} does not exist"
+ a.whyrun "Assuming source file #{new_resource.source} would have been created."
+ end
+ end
end
# load_current_resource is run in Chef::Provider#run_action when not in whyrun_mode?
diff --git a/spec/unit/provider/package/windows_spec.rb b/spec/unit/provider/package/windows_spec.rb
index d07e68cb5b..aed0ca88be 100644
--- a/spec/unit/provider/package/windows_spec.rb
+++ b/spec/unit/provider/package/windows_spec.rb
@@ -394,6 +394,25 @@ describe Chef::Provider::Package::Windows, :windows_only do
end
end
end
+
+ context "a missing local file is given" do
+ let(:resource_source) { "C:/a_missing_file.exe" }
+ let(:installer_type) { nil }
+ before do
+ allow(::File).to receive(:exist?).with(provider.new_resource.source).and_return(false)
+ provider.load_current_resource
+ end
+
+ it "raises a Package error" do
+ expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
+ end
+
+ it "why_run mode doesn't raise an error" do
+ Chef::Config[:why_run] = true
+ expect { provider.run_action(:install) }.not_to raise_error
+ Chef::Config[:why_run] = false
+ end
+ end
end
shared_context "valid checksum" do