diff options
author | Josh Barker <josh.barker.developer@gmail.com> | 2018-05-26 15:56:12 +1000 |
---|---|---|
committer | Josh Barker <josh.barker.developer@gmail.com> | 2018-05-26 15:58:23 +1000 |
commit | da8dcb98cf650708b6a9d44fa6ef2339e0b0f64c (patch) | |
tree | e837b886e8b8670eeb538be94467b6254c6b7e43 | |
parent | 2d687d12053e2888efa0441fa72f32faf6c7c5f7 (diff) | |
download | chef-da8dcb98cf650708b6a9d44fa6ef2339e0b0f64c.tar.gz |
Check local file exists before installing a windows package
Signed-off-by: Josh Barker <josh.barker.developer@gmail.com>
-rw-r--r-- | lib/chef/provider/package/windows.rb | 7 | ||||
-rw-r--r-- | spec/unit/provider/package/windows_spec.rb | 12 |
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/chef/provider/package/windows.rb b/lib/chef/provider/package/windows.rb index 0fea32dcf3..8958bff068 100644 --- a/lib/chef/provider/package/windows.rb +++ b/lib/chef/provider/package/windows.rb @@ -39,6 +39,13 @@ 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" + 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..0f4fd465c8 100644 --- a/spec/unit/provider/package/windows_spec.rb +++ b/spec/unit/provider/package/windows_spec.rb @@ -394,6 +394,18 @@ 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 } + + it "raises a Package error" do + allow(::File).to receive(:exist?).with(provider.new_resource.source).and_return(false) + + provider.load_current_resource + expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package) + end + end end shared_context "valid checksum" do |