summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Huff <nrhuff@umn.edu>2014-07-30 14:59:20 -0500
committerBryan McLellan <btm@getchef.com>2014-08-18 08:12:56 -0700
commit8467c750a56e728511f356049e15d1389e55870a (patch)
treea32c14077e0471b4c9a9f075cd13e5bed35184a9
parent78335936a30b96d9a0cd352026df095e31c6f9f7 (diff)
downloadchef-8467c750a56e728511f356049e15d1389e55870a.tar.gz
Break get_current_version into its own function.
Also add spec to check that the install action doesn't do an upgrade.
-rw-r--r--lib/chef/provider/package/ips.rb16
-rw-r--r--spec/unit/provider/package/ips_spec.rb63
2 files changed, 59 insertions, 20 deletions
diff --git a/lib/chef/provider/package/ips.rb b/lib/chef/provider/package/ips.rb
index 62e63d68c6..24e0903140 100644
--- a/lib/chef/provider/package/ips.rb
+++ b/lib/chef/provider/package/ips.rb
@@ -39,20 +39,26 @@ class Chef
end
end
+ def get_current_version
+ shell_out!("pkg info #{@new_resource.package_name}").stdout.each_line do |line|
+ return $1.split[0] if line =~ /^\s+Version: (.*)/
+ end
+ return nil
+ end
+
def get_candidate_version
shell_out!("pkg info -r #{new_resource.package_name}").stdout.each_line do |line|
- @candidate_version = $1.split[0] if line =~ /Version: (.*)/
+ return $1.split[0] if line =~ /Version: (.*)/
end
+ return nil
end
def load_current_resource
@current_resource = Chef::Resource::Package.new(@new_resource.name)
@current_resource.package_name(@new_resource.package_name)
Chef::Log.debug("Checking package status for #{@new_resource.name}")
- shell_out!("pkg info #{@new_resource.package_name}").stdout.each_line do |line|
- @current_resource.version($1.split[0]) if line =~ /^\s+Version: (.*)/
- end
- get_candidate_version
+ @current_resource.version(get_current_version)
+ @candidate_version = get_candidate_version
@current_resource
end
diff --git a/spec/unit/provider/package/ips_spec.rb b/spec/unit/provider/package/ips_spec.rb
index a972596c08..d5abfedf15 100644
--- a/spec/unit/provider/package/ips_spec.rb
+++ b/spec/unit/provider/package/ips_spec.rb
@@ -162,24 +162,57 @@ PKG_STATUS
@provider.candidate_version.should eql("1.8.4.1")
end
- context "using the ips_package resource" do
+ it "should not upgrade the package if it is already installed" do
+ local = local_output
+ local.stdout = <<-INSTALLED
+ Name: crypto/gnupg
+ Summary: GNU Privacy Guard
+ Description: A complete and free implementation of the OpenPGP Standard as
+ defined by RFC4880.
+ Category: Applications/System Utilities
+ State: Installed
+ Publisher: solaris
+ Version: 2.0.17
+ Build Release: 5.11
+ Branch: 0.175.0.0.0.2.537
+Packaging Date: October 19, 2011 09:14:50 AM
+ Size: 8.07 MB
+ FMRI: pkg://solaris/crypto/gnupg@2.0.17,5.11-0.175.0.0.0.2.537:20111019T091450Z
+INSTALLED
+ remote = remote_output
+ remote.stdout = <<-REMOTE
+ Name: crypto/gnupg
+ Summary: GNU Privacy Guard
+ Description: A complete and free implementation of the OpenPGP Standard as
+ defined by RFC4880.
+ Category: Applications/System Utilities
+ State: Not Installed
+ Publisher: solaris
+ Version: 2.0.18
+ Build Release: 5.11
+ Branch: 0.175.0.0.0.2.537
+Packaging Date: October 19, 2011 09:14:50 AM
+ Size: 8.07 MB
+ FMRI: pkg://solaris/crypto/gnupg@2.0.18,5.11-0.175.0.0.0.2.537:20111019T091450Z
+REMOTE
+
+ @provider.should_receive(:shell_out!).with("pkg info #{@new_resource.package_name}").and_return(local)
+ @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote)
+ @provider.load_current_resource
+ @provider.should_receive(:install_package).exactly(0).times
+ @provider.action_install
+ end
+
+ context "when accept_license is true" do
before do
- @new_resource = Chef::Resource::IpsPackage.new("crypto/gnupg", @run_context)
- @current_resource = Chef::Resource::IpsPackage.new("crypto/gnupg", @run_context)
- @provider = Chef::Provider::Package::Ips.new(@new_resource, @run_context)
+ @new_resource.stub(:accept_license).and_return(true)
end
- context "when accept_license is true" do
- before do
- @new_resource.stub(:accept_license).and_return(true)
- end
-
- it "should run pkg install with the --accept flag" do
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "pkg install -q --accept crypto/gnupg@2.0.17"
- })
- @provider.install_package("crypto/gnupg", "2.0.17")
- end
+ it "should run pkg install with the --accept flag" do
+ @provider.should_receive(:run_command_with_systems_locale).with({
+ :command => "pkg install -q --accept crypto/gnupg@2.0.17"
+ })
+ @provider.install_package("crypto/gnupg", "2.0.17")
end
end
end