diff options
-rw-r--r-- | lib/chef/provider/package.rb | 5 | ||||
-rw-r--r-- | spec/unit/provider/package/yum_spec.rb | 50 |
2 files changed, 51 insertions, 4 deletions
diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb index 2e8e29981b..6b429a400d 100644 --- a/lib/chef/provider/package.rb +++ b/lib/chef/provider/package.rb @@ -464,10 +464,7 @@ class Chef # @return [Array] new_version(s) as an array def new_version_array - @new_version_array ||= - [ new_resource.version ].flatten.map do |v| - ( v.nil? || v.empty? ) ? nil : v - end + [ new_resource.version ].flatten.map { |v| v.to_s.empty? ? nil : v } end # @todo: extract apt/dpkg specific preseeding to a helper class diff --git a/spec/unit/provider/package/yum_spec.rb b/spec/unit/provider/package/yum_spec.rb index 1ebd58d312..e878b92621 100644 --- a/spec/unit/provider/package/yum_spec.rb +++ b/spec/unit/provider/package/yum_spec.rb @@ -123,6 +123,26 @@ describe Chef::Provider::Package::Yum do expect(@provider.arch).to eq("noarch") end + describe "when version constraint in package_name" do + it "should set package_version if no existing package_name is found and new_package_name is available" do + @new_resource = Chef::Resource::Package.new('cups = 1.2.4-11.18.el5_2.3') + @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) + allow(@yum_cache).to receive(:package_available?) { |pkg| pkg == 'cups' ? true : false } + allow(@yum_cache).to receive(:packages_from_require) do |pkg| + [Chef::Provider::Package::Yum::RPMDbPackage.new("cups", "1.2.4-11.18.el5_2.3", "noarch", [], false, true, "base"), + Chef::Provider::Package::Yum::RPMDbPackage.new("cups", "1.2.4-11.18.el5_2.2", "noarch", [], false, true, "base"),] + end + expect(Chef::Log).to receive(:debug).exactly(1).times.with(%r{checking yum info}) + expect(Chef::Log).to receive(:debug).exactly(1).times.with(%r{installed version}) + expect(Chef::Log).to receive(:debug).exactly(1).times.with(%r{matched 2 packages,}) + @provider.load_current_resource + expect(@provider.new_resource.package_name).to eq("cups") + expect(@provider.new_resource.version).to eq("1.2.4-11.18.el5_2.3") + expect(@provider.send(:new_version_array)).to eq(["1.2.4-11.18.el5_2.3"]) + expect(@provider.send(:package_name_array)).to eq(["cups"]) + end + end + it "should not set the arch when an existing package_name is found" do @new_resource = Chef::Resource::YumPackage.new('testing.beta3') @yum_cache = double( @@ -2075,6 +2095,36 @@ describe "Chef::Provider::Package::Yum - Multi" do it "should return the current resouce" do expect(@provider.load_current_resource).to eql(@provider.current_resource) end + + describe "when version constraint in package_name" do + it "should set package_version if no existing package_name is found and new_package_name is available" do + @new_resource = Chef::Resource::Package.new(['cups = 1.2.4-11.18.el5_2.3', 'emacs = 24.4']) + @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) + allow(@yum_cache).to receive(:package_available?) { |pkg| %w(cups emacs).include?(pkg) ? true : false } + allow(@yum_cache).to receive(:candidate_version) do |pkg| + if pkg == 'cups' + "1.2.4-11.18.el5_2.3" + elsif pkg == 'emacs' + "24.4" + end + end + allow(@yum_cache).to receive(:packages_from_require) do |pkg| + if pkg.name == 'cups' + [Chef::Provider::Package::Yum::RPMDbPackage.new("cups", "1.2.4-11.18.el5_2.3", "noarch", [], false, true, "base")] + elsif pkg.name == 'emacs' + [Chef::Provider::Package::Yum::RPMDbPackage.new("emacs", "24.4", "noarch", [], false, true, "base")] + end + end + expect(Chef::Log).to receive(:debug).exactly(2).times.with(%r{matched 1 package,}) + expect(Chef::Log).to receive(:debug).exactly(1).times.with(%r{candidate version: \["1.2.4-11.18.el5_2.3", "24.4"\]}) + expect(Chef::Log).to receive(:debug).at_least(2).times.with(%r{checking yum info}) + @provider.load_current_resource + expect(@provider.new_resource.package_name).to eq(["cups", "emacs"]) + expect(@provider.new_resource.version).to eq(["1.2.4-11.18.el5_2.3", "24.4"]) + expect(@provider.send(:package_name_array)).to eq(["cups", "emacs"]) + expect(@provider.send(:new_version_array)).to eq(["1.2.4-11.18.el5_2.3", "24.4"]) + end + end end describe "when installing a package" do |