summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-09-27 18:28:03 -0700
committerGitHub <noreply@github.com>2018-09-27 18:28:03 -0700
commit061b1a2786d3718258c7caee142a0ca44a24846c (patch)
treef3e9f0465eeab9ff1a443e98f45b5bee9ce5687e
parenta5e2cf212cd016133e7bf86b9bd1afd448b29311 (diff)
parent271042fadd0319b9246f0f4a85f6a0712ae125ee (diff)
downloadchef-061b1a2786d3718258c7caee142a0ca44a24846c.tar.gz
Merge pull request #7701 from chef/lcg/allow-downgrade-pseudo-default
Change the allow_downgrade pseudo-default in the package provider superclass to true
-rw-r--r--lib/chef/provider/package.rb2
-rw-r--r--spec/unit/provider/package/rpm_spec.rb10
-rw-r--r--spec/unit/provider/package_spec.rb12
3 files changed, 16 insertions, 8 deletions
diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb
index 58a3f31b50..534a219ff5 100644
--- a/lib/chef/provider/package.rb
+++ b/lib/chef/provider/package.rb
@@ -671,7 +671,7 @@ class Chef
if new_resource.respond_to?("allow_downgrade")
new_resource.allow_downgrade
else
- false
+ true
end
end
diff --git a/spec/unit/provider/package/rpm_spec.rb b/spec/unit/provider/package/rpm_spec.rb
index 3682043dcd..284e201e92 100644
--- a/spec/unit/provider/package/rpm_spec.rb
+++ b/spec/unit/provider/package/rpm_spec.rb
@@ -1,7 +1,7 @@
#
# Author:: Joshua Timberman (<joshua@chef.io>)
# Author:: Daniel DeLeo (<dan@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,7 +29,7 @@ describe Chef::Provider::Package::Rpm do
let(:package_name) { "ImageMagick-c++" }
let(:new_resource) do
- Chef::Resource::Package.new(package_name).tap do |resource|
+ Chef::Resource::RpmPackage.new(package_name).tap do |resource|
resource.source(package_source)
end
end
@@ -51,7 +51,7 @@ describe Chef::Provider::Package::Rpm do
describe "when the package source is not valid" do
context "when source is not defiend" do
- let(:new_resource) { Chef::Resource::Package.new("ImageMagick-c++") }
+ let(:new_resource) { Chef::Resource::RpmPackage.new("ImageMagick-c++") }
it "should raise an exception when attempting any action" do
expect { provider.run_action(:any) }.to raise_error(Chef::Exceptions::Package)
@@ -405,10 +405,10 @@ describe Chef::Provider::Package::Rpm do
# let() bindings and such, we have to set the stub here and not in a
# before block.
allow(::File).to receive(:exist?).with(package_source).and_return(true)
- Chef::Resource::Package.new("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm")
+ Chef::Resource::RpmPackage.new("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm")
end
- let(:current_resource) { Chef::Resource::Package.new("ImageMagick-c++") }
+ let(:current_resource) { Chef::Resource::RpmPackage.new("ImageMagick-c++") }
it "should install from a path when the package is a path and the source is nil" do
expect(new_resource.source).to eq("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm")
diff --git a/spec/unit/provider/package_spec.rb b/spec/unit/provider/package_spec.rb
index 36b282c6ac..181ac40a1b 100644
--- a/spec/unit/provider/package_spec.rb
+++ b/spec/unit/provider/package_spec.rb
@@ -171,7 +171,7 @@ describe Chef::Provider::Package do
it "should print the word 'uninstalled' if there was no original version" do
allow(current_resource).to receive(:version).and_return(nil)
- expect(logger).to receive(:info).with("package[install emacs] upgraded emacs to 1.0")
+ expect(logger).to receive(:info).with("package[install emacs] upgraded(allow_downgrade) emacs to 1.0")
provider.run_action(:upgrade)
expect(new_resource).to be_updated_by_last_action
end
@@ -714,7 +714,15 @@ describe "Chef::Provider::Package - Multi" do
expect(new_resource).not_to be_updated_by_last_action
end
- it "does not install older version" do
+ it "does install an older version by default" do
+ current_resource.version(["1.1", "6.2"])
+ new_resource.version(["1.0", "6.1"])
+ provider.run_action(:install)
+ expect(new_resource).to be_updated_by_last_action
+ end
+
+ it "does not install an older version if the resource subclass has allow_downgrade set to false" do
+ allow(new_resource).to receive(:allow_downgrade).and_return(false)
current_resource.version(["1.1", "6.2"])
new_resource.version(["1.0", "6.1"])
provider.run_action(:install)