diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2015-11-23 19:59:02 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-12-02 13:41:33 -0800 |
commit | 602e09a72c6617ee01ca3febb519d3fd36bd2b8c (patch) | |
tree | 376938e5ee04b27b41f4e62ff511644455bfd82e /spec/unit | |
parent | de1f684f415faa54599c6b3abbe211d64a319aa6 (diff) | |
download | chef-602e09a72c6617ee01ca3febb519d3fd36bd2b8c.tar.gz |
dpkg multipackage and bonus fixes
- multipackages dpkg_package
- fixes edge conditions in load-current-resource around purging/removing
packages that threw errors before
- fixes the ability to purge packages that have been removed
- adds a lot of functional tests for dpkg_package
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/provider/package/dpkg_spec.rb | 79 | ||||
-rw-r--r-- | spec/unit/provider/package_spec.rb | 14 |
2 files changed, 43 insertions, 50 deletions
diff --git a/spec/unit/provider/package/dpkg_spec.rb b/spec/unit/provider/package/dpkg_spec.rb index 2ded8313c0..15b2903a0e 100644 --- a/spec/unit/provider/package/dpkg_spec.rb +++ b/spec/unit/provider/package/dpkg_spec.rb @@ -1,4 +1,3 @@ -# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 @@ -25,7 +24,7 @@ describe Chef::Provider::Package::Dpkg do let(:package) { "wget" } let(:source) { "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" } let(:new_resource) do - new_resource = Chef::Resource::Package.new(package) + new_resource = Chef::Resource::DpkgPackage.new(package) new_resource.source source new_resource end @@ -52,8 +51,8 @@ Conflicts: wget-ssl end before(:each) do - allow(provider).to receive(:shell_out!).with("dpkg-deb -W #{new_resource.source}", timeout: 900).and_return(dpkg_deb_status) - allow(provider).to receive(:shell_out).with("dpkg -s #{package}", timeout: 900).and_return(dpkg_s_status) + allow(provider).to receive(:shell_out!).with("dpkg-deb -W #{source}", timeout: 900).and_return(dpkg_deb_status) + allow(provider).to receive(:shell_out).with("dpkg -s #{package}", timeout: 900).and_return(double(stdout: "", exitstatus: -1)) allow(::File).to receive(:exist?).with(source).and_return(true) end @@ -112,16 +111,16 @@ Conflicts: wget-ssl it "should create a current resource with the name of the new_resource" do provider.load_current_resource - expect(provider.current_resource.package_name).to eq("wget") + expect(provider.current_resource.package_name).to eq(["wget"]) end describe 'gets the source package version from dpkg-deb' do def check_version(version) status = double(:stdout => "wget\t#{version}", :exitstatus => 0) - expect(provider).to receive(:shell_out!).with("dpkg-deb -W #{new_resource.source}", timeout: 900).and_return(status) + expect(provider).to receive(:shell_out!).with("dpkg-deb -W #{source}", timeout: 900).and_return(status) provider.load_current_resource - expect(provider.current_resource.package_name).to eq("wget") - expect(provider.candidate_version).to eq(version) + expect(provider.current_resource.package_name).to eq(["wget"]) + expect(provider.candidate_version).to eq([version]) end it 'if short version provided' do @@ -146,7 +145,7 @@ Conflicts: wget-ssl it "gets the source package name from dpkg-deb correctly" do provider.load_current_resource - expect(provider.current_resource.package_name).to eq("f.o.o-pkg++2") + expect(provider.current_resource.package_name).to eq(["f.o.o-pkg++2"]) end end @@ -157,21 +156,22 @@ Conflicts: wget-ssl it "gets the source package version from dpkg-deb correctly when the package version has `~', `-', `+' or `.' characters" do provider.load_current_resource - expect(provider.candidate_version).to eq('1.2.3+3141592-1ubuntu1~lucid') + expect(provider.candidate_version).to eq(['1.2.3+3141592-1ubuntu1~lucid']) end end - it "should raise an exception if the source is not set but we are installing" do - new_resource = Chef::Resource::Package.new("wget") - provider.new_resource = new_resource - provider.load_current_resource - provider.define_resource_requirements - expect { provider.run_action(:install)}.to raise_error(Chef::Exceptions::Package) + describe "when the source is not set" do + let(:source) { nil } + + it "should raise an exception if the source is not set but we are installing" do + expect { provider.run_action(:install)}.to raise_error(Chef::Exceptions::Package) + end end it "should return the current version installed if found by dpkg" do + allow(provider).to receive(:shell_out).with("dpkg -s #{package}", timeout: 900).and_return(dpkg_s_status) provider.load_current_resource - expect(provider.current_resource.version).to eq("1.11.4-1ubuntu1") + expect(provider.current_resource.version).to eq(["1.11.4-1ubuntu1"]) end it "should raise an exception if dpkg fails to run" do @@ -184,72 +184,73 @@ Conflicts: wget-ssl describe Chef::Provider::Package::Dpkg, "install and upgrade" do it "should run dpkg -i with the package source" do expect(provider).to receive(:run_noninteractive).with( - "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb" + "dpkg -i", nil, "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" ) - provider.install_package("wget", "1.11.4-1ubuntu1") + provider.load_current_resource + provider.run_action(:install) end it "should run dpkg -i if the package is a path and the source is nil" do - new_resource.name = "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" + new_resource.name "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" expect(provider).to receive(:run_noninteractive).with( - "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb" + "dpkg -i", nil, "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" ) - provider.install_package("/tmp/wget_1.11.4-1ubuntu1_amd64.deb", "1.11.4-1ubuntu1") + provider.run_action(:install) end it "should run dpkg -i if the package is a path and the source is nil for an upgrade" do - new_resource.name = "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" + new_resource.name "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" expect(provider).to receive(:run_noninteractive).with( - "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb" + "dpkg -i", nil, "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" ) - provider.upgrade_package("/tmp/wget_1.11.4-1ubuntu1_amd64.deb", "1.11.4-1ubuntu1") + provider.run_action(:upgrade) end it "should run dpkg -i with the package source and options if specified" do + new_resource.options "--force-yes" expect(provider).to receive(:run_noninteractive).with( - "dpkg -i --force-yes /tmp/wget_1.11.4-1ubuntu1_amd64.deb" + "dpkg -i", "--force-yes", "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" ) - allow(new_resource).to receive(:options).and_return("--force-yes") - - provider.install_package("wget", "1.11.4-1ubuntu1") + provider.run_action(:install) end + it "should upgrade by running install_package" do - expect(provider).to receive(:install_package).with("wget", "1.11.4-1ubuntu1") - provider.upgrade_package("wget", "1.11.4-1ubuntu1") + expect(provider).to receive(:install_package).with(["wget"], ["1.11.4-1ubuntu1"]) + provider.upgrade_package(["wget"], ["1.11.4-1ubuntu1"]) end end describe Chef::Provider::Package::Dpkg, "remove and purge" do it "should run dpkg -r to remove the package" do expect(provider).to receive(:run_noninteractive).with( - "dpkg -r wget" + "dpkg -r", nil, "wget" ) - provider.remove_package("wget", "1.11.4-1ubuntu1") + provider.remove_package(["wget"], ["1.11.4-1ubuntu1"]) end it "should run dpkg -r to remove the package with options if specified" do expect(provider).to receive(:run_noninteractive).with( - "dpkg -r --force-yes wget" + "dpkg -r", "--force-yes", "wget" ) allow(new_resource).to receive(:options).and_return("--force-yes") - provider.remove_package("wget", "1.11.4-1ubuntu1") + provider.remove_package(["wget"], ["1.11.4-1ubuntu1"]) end it "should run dpkg -P to purge the package" do expect(provider).to receive(:run_noninteractive).with( - "dpkg -P wget" + "dpkg -P", nil, "wget" ) - provider.purge_package("wget", "1.11.4-1ubuntu1") + provider.purge_package(["wget"], ["1.11.4-1ubuntu1"]) end it "should run dpkg -P to purge the package with options if specified" do expect(provider).to receive(:run_noninteractive).with( - "dpkg -P --force-yes wget" + "dpkg -P", "--force-yes", "wget" ) allow(new_resource).to receive(:options).and_return("--force-yes") - provider.purge_package("wget", "1.11.4-1ubuntu1") + provider.purge_package(["wget"], ["1.11.4-1ubuntu1"]) end end end diff --git a/spec/unit/provider/package_spec.rb b/spec/unit/provider/package_spec.rb index 9e4384820a..d8f669e6a4 100644 --- a/spec/unit/provider/package_spec.rb +++ b/spec/unit/provider/package_spec.rb @@ -453,17 +453,9 @@ describe "Subclass with use_multipackage_api" do provider end - it "should have supports_arrays class accessor" do - expect(MyPackageProvider.supports_arrays).to be true - MyPackageProvider.supports_arrays = false - expect(MyPackageProvider.supports_arrays).to be false - # class variables are global state, so better set it back... - MyPackageProvider.supports_arrays = true - end - - it "has supports_arrays? methods on the class and instance" do - expect(MyPackageProvider.supports_arrays?).to be true - expect(provider.supports_arrays?).to be true + it "has use_multipackage_api? methods on the class and instance" do + expect(MyPackageProvider.use_multipackage_api?).to be true + expect(provider.use_multipackage_api?).to be true end it "when user passes string to package_name, passes arrays to install_package" do |