diff options
| author | Tor Magnus Rakvåg <tm@intility.no> | 2018-02-12 14:08:17 +0100 |
|---|---|---|
| committer | Tor Magnus Rakvåg <tm@intility.no> | 2018-02-12 14:20:19 +0100 |
| commit | 67fd2daf3151fd3a6eaee90a11aa5792e01e8159 (patch) | |
| tree | 3b6a4c3ddf8681a27dc17c15e8628ad61d33e75e /spec | |
| parent | baba34bdf0fd079f6bde0f7f0f28929c084543ba (diff) | |
| download | chef-67fd2daf3151fd3a6eaee90a11aa5792e01e8159.tar.gz | |
add source param
Signed-off-by: Tor Magnus Rakvåg tm@intility.no
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/unit/provider/package/powershell_spec.rb | 51 | ||||
| -rw-r--r-- | spec/unit/resource/powershell_package_spec.rb | 9 |
2 files changed, 60 insertions, 0 deletions
diff --git a/spec/unit/provider/package/powershell_spec.rb b/spec/unit/provider/package/powershell_spec.rb index fc53eea12d..c9fb5b69ca 100644 --- a/spec/unit/provider/package/powershell_spec.rb +++ b/spec/unit/provider/package/powershell_spec.rb @@ -22,6 +22,7 @@ require "chef/mixin/powershell_out" describe Chef::Provider::Package::Powershell do include Chef::Mixin::PowershellOut let(:timeout) { 900 } + let(:source) { nil } let(:new_resource) { Chef::Resource::PowershellPackage.new("windows_test_pkg") } @@ -107,6 +108,14 @@ describe Chef::Provider::Package::Powershell do expect(provider.candidate_version).to eql(["2.12.0.0"]) end + it "should use the candidate_version from the correct source" do + allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap -Source MyGallery ).Version", {:timeout => new_resource.timeout }).and_return(package_xnetworking_available) + new_resource.package_name(["xNetworking"]) + new_resource.version(nil) + new_resource.source("MyGallery") + expect(provider.candidate_version).to eql(["2.12.0.0"]) + end + it "should set the candidate_version to the latest version when not pinning and package name is space seperated" do allow(provider).to receive(:powershell_out).with("( Find-Package '7-Zip 16.02 (x64)' -Force -ForceBootstrap ).Version", { :timeout => new_resource.timeout }).and_return(package_7zip_available) new_resource.package_name(["7-Zip 16.02 (x64)"]) @@ -182,6 +191,19 @@ describe Chef::Provider::Package::Powershell do expect(new_resource).to be_updated_by_last_action end + it "should install a single package from a custom source" do + provider.load_current_resource + new_resource.package_name(["xCertificate"]) + new_resource.version(nil) + new_resource.source("MyGallery") + allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -Source MyGallery ).Version", { :timeout => new_resource.timeout }).and_return(package_xcertificate_available) + allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap ).Version", { :timeout => new_resource.timeout }).and_return(package_xcertificate_not_available) + allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version) + expect(provider).to receive(:powershell_out).with("( Install-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 -Source MyGallery ).Version", { :timeout => new_resource.timeout }) + provider.run_action(:install) + expect(new_resource).to be_updated_by_last_action + end + it "should install a single package when package name has space in between" do provider.load_current_resource new_resource.package_name(["7-Zip 16.02 (x64)"]) @@ -281,6 +303,22 @@ describe Chef::Provider::Package::Powershell do provider.run_action(:install) expect(new_resource).to be_updated_by_last_action end + + it "should do multipackage installs from a custom source when given two packages without constraints" do + new_resource.package_name(%w{xCertificate xNetworking}) + new_resource.version(nil) + new_resource.source("MyGallery") + allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -Source MyGallery ).Version", { :timeout => new_resource.timeout }).and_return(package_xcertificate_available) + allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap ).Version", { :timeout => new_resource.timeout }).and_return(package_xcertificate_not_available) + allow(provider).to receive(:powershell_out).with("( Find-Package 'xNetworking' -Force -ForceBootstrap -Source MyGallery ).Version", { :timeout => new_resource.timeout }).and_return(package_xnetworking_available) + allow(provider).to receive(:powershell_out).with("( Get-Package 'xNetworking' -Force -ForceBootstrap ).Version", { :timeout => new_resource.timeout }).and_return(package_xnetworking_not_available) + allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version) + expect(provider).to receive(:powershell_out).with("( Install-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 -Source MyGallery ).Version", { :timeout => new_resource.timeout }) + expect(provider).to receive(:powershell_out).with("( Install-Package 'xNetworking' -Force -ForceBootstrap -RequiredVersion 2.12.0.0 -Source MyGallery ).Version", { :timeout => new_resource.timeout }) + provider.load_current_resource + provider.run_action(:install) + expect(new_resource).to be_updated_by_last_action + end end describe "#action_remove" do @@ -296,6 +334,19 @@ describe Chef::Provider::Package::Powershell do expect(new_resource).not_to be_updated_by_last_action end + it "does not pass the source parameter to get or uninstall cmdlets" do + new_resource.package_name(["xCertificate"]) + new_resource.version(["2.1.0.0"]) + new_resource.source("MyGallery") + allow(provider).to receive(:powershell_out).with("( Find-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 -Source MyGallery).Version", { :timeout => new_resource.timeout }).and_return(package_xcertificate_available) + allow(provider).to receive(:powershell_out).with("( Get-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 ).Version", { :timeout => new_resource.timeout }).and_return(package_xcertificate_available) + allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version) + provider.load_current_resource + expect(provider).to receive(:powershell_out).with("( Uninstall-Package 'xCertificate' -Force -ForceBootstrap -RequiredVersion 2.1.0.0 ).Version", { :timeout => new_resource.timeout }) + provider.run_action(:remove) + expect(new_resource).to be_updated_by_last_action + end + it "does nothing when all the packages are already removed" do new_resource.package_name(%w{xCertificate xNetworking}) new_resource.version(nil) diff --git a/spec/unit/resource/powershell_package_spec.rb b/spec/unit/resource/powershell_package_spec.rb index 701014bd95..a448d58d5a 100644 --- a/spec/unit/resource/powershell_package_spec.rb +++ b/spec/unit/resource/powershell_package_spec.rb @@ -63,4 +63,13 @@ describe Chef::Resource::PowershellPackage do resource.version(["1.2.3", "4.5.6"]) expect(resource.version).to eql(["1.2.3", "4.5.6"]) end + + it "the default source is nil" do + expect(resource.source).to eql(nil) + end + + it "the source setter accepts strings" do + resource.source("MyGallery") + expect(resource.source).to eql("MyGallery") + end end |
