summaryrefslogtreecommitdiff
path: root/spec/unit/provider/package/ips_spec.rb
diff options
context:
space:
mode:
authorNathan Huff <nrhuff@umn.edu>2014-07-28 15:20:55 -0500
committerBryan McLellan <btm@getchef.com>2014-08-18 08:12:56 -0700
commit78335936a30b96d9a0cd352026df095e31c6f9f7 (patch)
treea38fecb458c9d868303150d605f20ddafc3b897a /spec/unit/provider/package/ips_spec.rb
parentb06510323102fcb35fb7b02891591b3a540ddf27 (diff)
downloadchef-78335936a30b96d9a0cd352026df095e31c6f9f7.tar.gz
Check local repository as well as remote when looking up the currently installed packages
Diffstat (limited to 'spec/unit/provider/package/ips_spec.rb')
-rw-r--r--spec/unit/provider/package/ips_spec.rb99
1 files changed, 51 insertions, 48 deletions
diff --git a/spec/unit/provider/package/ips_spec.rb b/spec/unit/provider/package/ips_spec.rb
index 53f8169623..a972596c08 100644
--- a/spec/unit/provider/package/ips_spec.rb
+++ b/spec/unit/provider/package/ips_spec.rb
@@ -31,53 +31,72 @@ describe Chef::Provider::Package::Ips do
Chef::Resource::Package.stub(:new).and_return(@current_resource)
@provider = Chef::Provider::Package::Ips.new(@new_resource, @run_context)
- @stdin = StringIO.new
- @stderr = StringIO.new
- @stdout =<<-PKG_STATUS
- 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.17
+ @local = local_output
+ @remote = remote_output
+ end
+
+ def local_output
+ stdin = StringIO.new
+ stdout = ''
+ stderr =<<-PKG_STATUS
+pkg: info: no packages matching the following patterns you specified are
+installed on the system. Try specifying -r to query remotely:
+
+ crypto/gnupg
+PKG_STATUS
+ return OpenStruct.new(:stdout => stdout,:stdin => stdin,:stderr => stderr,:status => @status,:exitstatus => 1)
+ end
+
+ def remote_output
+
+ stdout = <<-PKG_STATUS
+ Name: security/sudo
+ Summary: sudo - authority delegation tool
+ State: Not Installed
+ Publisher: omnios
+ Version: 1.8.4.1 (1.8.4p1)
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
+ Branch: 0.151002
+Packaging Date: April 1, 2012 05:55:52 PM
+ Size: 2.57 MB
+ FMRI: pkg://omnios/security/sudo@1.8.4.1,5.11-0.151002:20120401T175552Z
PKG_STATUS
- @pid = 12345
- @shell_out = OpenStruct.new(:stdout => @stdout,:stdin => @stdin,:stderr => @stderr,:status => @status,:exitstatus => 0)
+ stdin = StringIO.new
+ stderr = ''
+ return OpenStruct.new(:stdout => stdout,:stdin => stdin,:stderr => stderr,:status => @status,:exitstatus => 0)
end
context "when loading current resource" do
it "should create a current resource with the name of the new_resource" do
- @provider.should_receive(:shell_out!).and_return(@shell_out)
+ @provider.should_receive(:shell_out!).with("pkg info #{@new_resource.package_name}").and_return(local_output)
+ @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output)
Chef::Resource::Package.should_receive(:new).and_return(@current_resource)
@provider.load_current_resource
end
it "should set the current resources package name to the new resources package name" do
- @provider.should_receive(:shell_out!).and_return(@shell_out)
- @current_resource.should_receive(:package_name).with(@new_resource.package_name)
+ @provider.should_receive(:shell_out!).with("pkg info #{@new_resource.package_name}").and_return(local_output)
+ @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output)
@provider.load_current_resource
+ @current_resource.package_name.should == @new_resource.package_name
end
it "should run pkg info with the package name" do
- @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(@shell_out)
+ @provider.should_receive(:shell_out!).with("pkg info #{@new_resource.package_name}").and_return(local_output)
+ @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output)
@provider.load_current_resource
end
it "should set the installed version to nil on the current resource if package state is not installed" do
- @provider.should_receive(:shell_out!).and_return(@shell_out)
- @current_resource.should_receive(:version).with(nil).and_return(true)
+ @provider.should_receive(:shell_out!).with("pkg info #{@new_resource.package_name}").and_return(local_output)
+ @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output)
@provider.load_current_resource
+ @current_resource.version.should be_nil
end
it "should set the installed version if package has one" do
- @stdout.replace(<<-INSTALLED)
+ local = local_output
+ local.stdout = <<-INSTALLED
Name: crypto/gnupg
Summary: GNU Privacy Guard
Description: A complete and free implementation of the OpenPGP Standard as
@@ -92,14 +111,15 @@ 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
- @provider.should_receive(:shell_out!).and_return(@shell_out)
+ @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_output)
@provider.load_current_resource
@current_resource.version.should == "2.0.17"
- @provider.candidate_version.should eql("2.0.17")
end
it "should return the current resouce" do
- @provider.should_receive(:shell_out!).and_return(@shell_out)
+ @provider.should_receive(:shell_out!).with("pkg info #{@new_resource.package_name}").and_return(local_output)
+ @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output)
@provider.load_current_resource.should eql(@current_resource)
end
end
@@ -121,27 +141,9 @@ INSTALLED
@provider.install_package("crypto/gnupg", "2.0.17")
end
- it "should not contain invalid characters for the version string" do
- @stdout.replace(<<-PKG_STATUS)
- Name: security/sudo
- Summary: sudo - authority delegation tool
- State: Not Installed
- Publisher: omnios
- Version: 1.8.4.1 (1.8.4p1)
- Build Release: 5.11
- Branch: 0.151002
-Packaging Date: April 1, 2012 05:55:52 PM
- Size: 2.57 MB
- FMRI: pkg://omnios/security/sudo@1.8.4.1,5.11-0.151002:20120401T175552Z
-PKG_STATUS
- @provider.should_receive(:run_command_with_systems_locale).with({
- :command => "pkg install -q security/sudo@1.8.4.1"
- })
- @provider.install_package("security/sudo", "1.8.4.1")
- end
-
it "should not include the human-readable version in the candidate_version" do
- @stdout.replace(<<-PKG_STATUS)
+ remote = remote_output
+ remote.stdout = <<-PKG_STATUS
Name: security/sudo
Summary: sudo - authority delegation tool
State: Not Installed
@@ -153,7 +155,8 @@ Packaging Date: April 1, 2012 05:55:52 PM
Size: 2.57 MB
FMRI: pkg://omnios/security/sudo@1.8.4.1,5.11-0.151002:20120401T175552Z
PKG_STATUS
- @provider.should_receive(:shell_out!).and_return(@shell_out)
+ @provider.should_receive(:shell_out!).with("pkg info #{@new_resource.package_name}").and_return(local_output)
+ @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote)
@provider.load_current_resource
@current_resource.version.should be_nil
@provider.candidate_version.should eql("1.8.4.1")