diff options
author | Thom May <thom@may.lt> | 2018-06-01 11:04:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-01 11:04:58 +0100 |
commit | 52786b7bd9f7b7cdd3cdd9962e64ab104f9e17ec (patch) | |
tree | aae43379ee9c92bfa45b6be36b1a05489f4193f9 | |
parent | a3ced2c6b92d842ea93515337e575fd1f18dad17 (diff) | |
parent | da8dcb98cf650708b6a9d44fa6ef2339e0b0f64c (diff) | |
download | chef-52786b7bd9f7b7cdd3cdd9962e64ab104f9e17ec.tar.gz |
Merge pull request #7299 from josh-barker/josh-barker/windows-package-missing-source
Check local file exists before installing a windows package
-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 |