diff options
-rw-r--r-- | lib/chef/provider/package/yum.rb | 6 | ||||
-rw-r--r-- | lib/chef/resource/yum_package.rb | 2 | ||||
-rw-r--r-- | spec/unit/provider/package/yum_spec.rb | 40 | ||||
-rw-r--r-- | spec/unit/resource/yum_package_spec.rb | 12 |
4 files changed, 47 insertions, 13 deletions
diff --git a/lib/chef/provider/package/yum.rb b/lib/chef/provider/package/yum.rb index de23ed22b9..81454380a3 100644 --- a/lib/chef/provider/package/yum.rb +++ b/lib/chef/provider/package/yum.rb @@ -986,7 +986,11 @@ class Chef end def yum_binary - new_resource.is_a?(Chef::Resource::YumPackage) ? new_resource.yum_binary : "yum" + @yum_binary ||= + begin + yum_binary = new_resource.yum_binary if new_resource.is_a?(Chef::Resource::YumPackage) + yum_binary ||= ::File.exist?("/usr/bin/yum-deprecated") ? "yum-deprecated" : "yum" + end end # Extra attributes diff --git a/lib/chef/resource/yum_package.rb b/lib/chef/resource/yum_package.rb index df50022157..50ba13ce65 100644 --- a/lib/chef/resource/yum_package.rb +++ b/lib/chef/resource/yum_package.rb @@ -28,7 +28,7 @@ class Chef super @flush_cache = { :before => false, :after => false } @allow_downgrade = false - @yum_binary = ::File.exist?("/usr/bin/yum-deprecated") ? "yum-deprecated" : "yum" + @yum_binary = nil end # Install a specific arch diff --git a/spec/unit/provider/package/yum_spec.rb b/spec/unit/provider/package/yum_spec.rb index fa8751bacc..3fc0b807c9 100644 --- a/spec/unit/provider/package/yum_spec.rb +++ b/spec/unit/provider/package/yum_spec.rb @@ -89,6 +89,46 @@ describe Chef::Provider::Package::Yum do end end + describe "yum_binary accessor" do + it "when yum-deprecated exists" do + expect(File).to receive(:exist?).with("/usr/bin/yum-deprecated").and_return(true) + expect(@yum_cache).to receive(:yum_binary=).with("yum-deprecated") + @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) + expect(@provider.yum_binary).to eql("yum-deprecated") + end + + it "when yum-deprecated does not exist" do + expect(File).to receive(:exist?).with("/usr/bin/yum-deprecated").and_return(false) + expect(@yum_cache).to receive(:yum_binary=).with("yum") + @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) + expect(@provider.yum_binary).to eql("yum") + end + + it "when the yum_binary is set on the resource" do + @new_resource.yum_binary "/usr/bin/yum-something" + expect(File).not_to receive(:exist?) + expect(@yum_cache).to receive(:yum_binary=).with("/usr/bin/yum-something") + @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) + expect(@provider.yum_binary).to eql("/usr/bin/yum-something") + end + + it "when the new_resource is a vanilla package class and yum-deprecated exists" do + @new_resource = Chef::Resource::Package.new('cups') + expect(File).to receive(:exist?).with("/usr/bin/yum-deprecated").and_return(true) + expect(@yum_cache).to receive(:yum_binary=).with("yum-deprecated") + @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) + expect(@provider.yum_binary).to eql("yum-deprecated") + end + + it "when the new_resource is a vanilla package class and yum-deprecated does not exist" do + @new_resource = Chef::Resource::Package.new('cups') + expect(File).to receive(:exist?).with("/usr/bin/yum-deprecated").and_return(false) + expect(@yum_cache).to receive(:yum_binary=).with("yum") + @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) + expect(@provider.yum_binary).to eql("yum") + end + end + describe "when arch in package_name" do it "should set the arch if no existing package_name is found and new_package_name+new_arch is available" do @new_resource = Chef::Resource::YumPackage.new('testing.noarch') diff --git a/spec/unit/resource/yum_package_spec.rb b/spec/unit/resource/yum_package_spec.rb index 79fc1965b9..f24f1e3405 100644 --- a/spec/unit/resource/yum_package_spec.rb +++ b/spec/unit/resource/yum_package_spec.rb @@ -82,17 +82,7 @@ end describe Chef::Resource::YumPackage, "yum_binary" do let(:resource) { Chef::Resource::YumPackage.new("foo") } - it "defaults to yum if yum-deprecated does not exist" do - expect(::File).to receive(:exist?).with("/usr/bin/yum-deprecated").and_return(false) - expect(resource.yum_binary).to eql("yum") - end - - it "defaults to yum-deprecated if yum-deprecated does exist" do - expect(::File).to receive(:exist?).with("/usr/bin/yum-deprecated").and_return(true) - expect(resource.yum_binary).to eql("yum-deprecated") - end - - it "should allow you to specify whether allow_downgrade is true or false" do + it "should allow you to specify the yum_binary" do resource.yum_binary "/usr/bin/yum-something" expect(resource.yum_binary).to eql("/usr/bin/yum-something") end |