diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2015-12-02 19:37:36 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-12-02 19:37:36 -0800 |
commit | 98d553ced4bde95210fac82006c9be24ddb8f817 (patch) | |
tree | 84354ce72351f2c7aacabd4bdee1be63addf2725 /spec/unit | |
parent | 2a610564a8a42208adf2158a7c5c0657b243d58a (diff) | |
parent | 2046cb8e519817619472384296328f9cdcbb5c16 (diff) | |
download | chef-98d553ced4bde95210fac82006c9be24ddb8f817.tar.gz |
Merge pull request #4196 from chef/lcg/dpkg-multipackage
multipackage dpkg_package and bonus fixes
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/mixin/subclass_directive_spec.rb | 45 | ||||
-rw-r--r-- | spec/unit/provider/package/dpkg_spec.rb | 79 | ||||
-rw-r--r-- | spec/unit/provider/package_spec.rb | 14 |
3 files changed, 90 insertions, 48 deletions
diff --git a/spec/unit/mixin/subclass_directive_spec.rb b/spec/unit/mixin/subclass_directive_spec.rb new file mode 100644 index 0000000000..552f26c0c1 --- /dev/null +++ b/spec/unit/mixin/subclass_directive_spec.rb @@ -0,0 +1,45 @@ +# +# Copyright:: Copyright (c) 2015 Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +class SubclassDirectiveParent + extend Chef::Mixin::SubclassDirective + + subclass_directive :behave_differently +end + +class SubclassDirectiveChild < SubclassDirectiveParent + behave_differently +end + +class ChildWithoutDirective < SubclassDirectiveParent +end + +describe Chef::Mixin::Uris do + let (:child) { SubclassDirectiveChild.new } + + let (:other_child) { ChildWithoutDirective.new } + + it "the child instance has the directive set" do + expect(child.behave_differently?).to be true + end + + it "a child that does not declare it does not have it set" do + expect(other_child.behave_differently?).to be false + end +end 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..f77c2b5d0d 100644 --- a/spec/unit/provider/package_spec.rb +++ b/spec/unit/provider/package_spec.rb @@ -453,17 +453,13 @@ 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 + 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 "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 "offers a_to_s to subclasses to convert an array of strings to a single string" do + expect(provider.send(:a_to_s, "a", nil, "b", "", "c", " ", "d e", "f-g")).to eq("a b c d e f-g") end it "when user passes string to package_name, passes arrays to install_package" do |