diff options
author | kaustubh-d <kaustubh@clogeny.com> | 2014-11-18 14:56:22 +0530 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2015-02-17 09:16:38 -0500 |
commit | 6909f4074dbd9cee5906333f693bd282476a6ac5 (patch) | |
tree | 7deb7fcea3b0409b23986f317649f8ec18fa241e /spec | |
parent | aa9b233614da81c506929cc1c36eb509a4e2c97e (diff) | |
download | chef-6909f4074dbd9cee5906333f693bd282476a6ac5.tar.gz |
fix aix related providers to replace popen4 with mixlib shell_out
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/functional/resource/aix_service_spec.rb | 3 | ||||
-rw-r--r-- | spec/functional/version_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/provider/group/dscl_spec.rb | 13 | ||||
-rw-r--r-- | spec/unit/provider/ifconfig/aix_spec.rb | 5 | ||||
-rw-r--r-- | spec/unit/provider/ifconfig_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/provider/mount/mount_spec.rb | 12 | ||||
-rw-r--r-- | spec/unit/provider/package/aix_spec.rb | 43 | ||||
-rw-r--r-- | spec/unit/provider/package/dpkg_spec.rb | 26 | ||||
-rw-r--r-- | spec/unit/provider/package/macports_spec.rb | 28 | ||||
-rw-r--r-- | spec/unit/provider/package/pacman_spec.rb | 29 | ||||
-rw-r--r-- | spec/unit/provider/package/portage_spec.rb | 22 | ||||
-rw-r--r-- | spec/unit/provider/package/solaris_spec.rb | 45 | ||||
-rw-r--r-- | spec/unit/provider/package/zypper_spec.rb | 21 |
13 files changed, 124 insertions, 129 deletions
diff --git a/spec/functional/resource/aix_service_spec.rb b/spec/functional/resource/aix_service_spec.rb index 6008fdea8f..9dec87db93 100755 --- a/spec/functional/resource/aix_service_spec.rb +++ b/spec/functional/resource/aix_service_spec.rb @@ -73,6 +73,9 @@ shared_examples "src service" do end describe Chef::Resource::Service, :requires_root, :aix_only do + + include Chef::Mixin::ShellOut + def get_user_id shell_out("id -u #{ENV['USER']}").stdout.chomp end diff --git a/spec/functional/version_spec.rb b/spec/functional/version_spec.rb index 71ba4d5b2f..cd5bbc7678 100644 --- a/spec/functional/version_spec.rb +++ b/spec/functional/version_spec.rb @@ -28,7 +28,7 @@ describe "Chef Versions" do binaries.each do |binary| it "#{binary} version should be sane" do - expect(shell_out!("ruby #{File.join("bin", binary)} -v", :cwd => chef_dir).stdout.chomp).to eq("Chef: #{Chef::VERSION}") + expect(shell_out!("ruby #{File.join("bin", binary)} -v", :cwd => chef_dir).stdout.chomp).to include("Chef: #{Chef::VERSION}") end end diff --git a/spec/unit/provider/group/dscl_spec.rb b/spec/unit/provider/group/dscl_spec.rb index e09365a828..d84e4e1d57 100644 --- a/spec/unit/provider/group/dscl_spec.rb +++ b/spec/unit/provider/group/dscl_spec.rb @@ -27,16 +27,13 @@ describe Chef::Provider::Group::Dscl do @current_resource = Chef::Resource::Group.new("aj") @provider = Chef::Provider::Group::Dscl.new(@new_resource, @run_context) @provider.current_resource = @current_resource - @status = double("Process::Status", :exitstatus => 0) - @pid = 2342 - @stdin = StringIO.new - @stdout = StringIO.new("\n") - @stderr = StringIO.new("") - allow(@provider).to receive(:popen4).and_yield(@pid,@stdin,@stdout,@stderr).and_return(@status) + + @status = double(:stdout => "\n", :stderr => "", :exitstatus => 0) + allow(@provider).to receive(:shell_out).and_return(@status) end - it "should run popen4 with the supplied array of arguments appended to the dscl command" do - expect(@provider).to receive(:popen4).with("dscl . -cmd /Path arg1 arg2") + it "should run shell_out with the supplied array of arguments appended to the dscl command" do + expect(@provider).to receive(:shell_out).with("dscl . -cmd /Path arg1 arg2") @provider.dscl("cmd", "/Path", "arg1", "arg2") end diff --git a/spec/unit/provider/ifconfig/aix_spec.rb b/spec/unit/provider/ifconfig/aix_spec.rb index 6e685823ac..0b6fa33614 100644 --- a/spec/unit/provider/ifconfig/aix_spec.rb +++ b/spec/unit/provider/ifconfig/aix_spec.rb @@ -49,10 +49,11 @@ IFCONFIG describe "#load_current_resource" do before do - status = double("Status", :exitstatus => 0) - expect(@provider).to receive(:popen4).with("ifconfig -a").and_yield(@pid,@stdin,StringIO.new(@ifconfig_output),@stderr).and_return(status) + @status = double(:stdout => @ifconfig_output, :exitstatus => 0) + allow(@provider).to receive(:shell_out).and_return(@status) @new_resource.device "en0" end + it "should load given interface with attributes." do current_resource = @provider.load_current_resource expect(current_resource.inet_addr).to eq("172.29.174.58") diff --git a/spec/unit/provider/ifconfig_spec.rb b/spec/unit/provider/ifconfig_spec.rb index 126112dd43..d290ab7066 100644 --- a/spec/unit/provider/ifconfig_spec.rb +++ b/spec/unit/provider/ifconfig_spec.rb @@ -42,8 +42,8 @@ describe Chef::Provider::Ifconfig do end describe Chef::Provider::Ifconfig, "load_current_resource" do before do - status = double("Status", :exitstatus => 1) - expect(@provider).to receive(:popen4).and_return status + @status = double(:stdout => "", :exitstatus => 1) + allow(@provider).to receive(:shell_out).and_return(@status) @provider.load_current_resource end it "should track state of ifconfig failure." do diff --git a/spec/unit/provider/mount/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb index 7e9531a8ac..7a37ffe74e 100644 --- a/spec/unit/provider/mount/mount_spec.rb +++ b/spec/unit/provider/mount/mount_spec.rb @@ -54,10 +54,11 @@ describe Chef::Provider::Mount::Mount do end it "should accecpt device_type :uuid", :not_supported_on_solaris do + @status = double(:stdout => "/dev/sdz1\n", :exitstatus => 1) @new_resource.device_type :uuid @new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a" @stdout_findfs = double("STDOUT", :first => "/dev/sdz1") - expect(@provider).to receive(:popen4).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_yield(@pid,@stdin,@stdout_findfs,@stderr).and_return(@status) + expect(@provider).to receive(:shell_out).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_return(@status) @provider.load_current_resource() @provider.mountable? end @@ -93,11 +94,10 @@ describe Chef::Provider::Mount::Mount do end it "should raise an error if the mount device (uuid) does not exist", :not_supported_on_solaris do + status = double(:stdout => "", :exitstatus => 1) @new_resource.device_type :uuid @new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a" - status_findfs = double("Status", :exitstatus => 1) - stdout_findfs = double("STDOUT", :first => nil) - expect(@provider).to receive(:popen4).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_yield(@pid,@stdin,stdout_findfs,@stderr).and_return(status_findfs) + expect(@provider).to receive(:shell_out).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_return(status) expect(::File).to receive(:exists?).with("").and_return(false) expect { @provider.load_current_resource();@provider.mountable? }.to raise_error(Chef::Exceptions::Mount) end @@ -307,10 +307,10 @@ describe Chef::Provider::Mount::Mount do end it "should mount the filesystem specified by uuid", :not_supported_on_solaris do + status = double(:stdout => "/dev/sdz1\n", :exitstatus => 1) @new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a" @new_resource.device_type :uuid - @stdout_findfs = double("STDOUT", :first => "/dev/sdz1") - allow(@provider).to receive(:popen4).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_yield(@pid,@stdin,@stdout_findfs,@stderr).and_return(@status) + allow(@provider).to receive(:shell_out).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_return(status) @stdout_mock = double('stdout mock') allow(@stdout_mock).to receive(:each).and_yield("#{@new_resource.device} on #{@new_resource.mount_point}") expect(@provider).to receive(:shell_out!).with("mount -t #{@new_resource.fstype} -o defaults -U #{@new_resource.device} #{@new_resource.mount_point}").and_return(@stdout_mock) diff --git a/spec/unit/provider/package/aix_spec.rb b/spec/unit/provider/package/aix_spec.rb index a39ab096c7..5bc861b849 100644 --- a/spec/unit/provider/package/aix_spec.rb +++ b/spec/unit/provider/package/aix_spec.rb @@ -36,23 +36,23 @@ describe Chef::Provider::Package::Aix do @bffinfo ="/usr/lib/objrepos:samba.base:3.3.12.0::COMMITTED:I:Samba for AIX: /etc/objrepos:samba.base:3.3.12.0::COMMITTED:I:Samba for AIX:" - @status = double("Status", :exitstatus => 0) + @status = double("Status", :stdout => "", :exitstatus => 0) end it "should create a current resource with the name of new_resource" do - allow(@provider).to receive(:popen4).and_return(@status) + allow(@provider).to receive(:shell_out).and_return(@status) @provider.load_current_resource expect(@provider.current_resource.name).to eq("samba.base") end it "should set the current resource bff package name to the new resource bff package name" do - allow(@provider).to receive(:popen4).and_return(@status) + allow(@provider).to receive(:shell_out).and_return(@status) @provider.load_current_resource expect(@provider.current_resource.package_name).to eq("samba.base") end it "should raise an exception if a source is supplied but not found" do - allow(@provider).to receive(:popen4).and_return(@status) + allow(@provider).to receive(:shell_out).and_return(@status) allow(::File).to receive(:exists?).and_return(false) @provider.load_current_resource @provider.define_resource_requirements @@ -60,10 +60,9 @@ describe Chef::Provider::Package::Aix do end it "should get the source package version from lslpp if provided" do - @stdout = StringIO.new(@bffinfo) - @stdin, @stderr = StringIO.new, StringIO.new - expect(@provider).to receive(:popen4).with("installp -L -d /tmp/samba.base").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) - expect(@provider).to receive(:popen4).with("lslpp -lcq samba.base").and_return(@status) + status = double("Status", :stdout => @bffinfo, :exitstatus => 0) + expect(@provider).to receive(:shell_out).with("installp -L -d /tmp/samba.base").and_return(status) + expect(@provider).to receive(:shell_out).with("lslpp -lcq samba.base").and_return(@status) @provider.load_current_resource expect(@provider.current_resource.package_name).to eq("samba.base") @@ -71,31 +70,33 @@ describe Chef::Provider::Package::Aix do end it "should return the current version installed if found by lslpp" do + status = double("Status", :stdout => @bffinfo, :exitstatus => 0) @stdout = StringIO.new(@bffinfo) @stdin, @stderr = StringIO.new, StringIO.new - expect(@provider).to receive(:popen4).with("installp -L -d /tmp/samba.base").and_return(@status) - expect(@provider).to receive(:popen4).with("lslpp -lcq samba.base").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect(@provider).to receive(:shell_out).with("installp -L -d /tmp/samba.base").and_return(@status) + expect(@provider).to receive(:shell_out).with("lslpp -lcq samba.base").and_return(status) @provider.load_current_resource expect(@provider.current_resource.version).to eq("3.3.12.0") end it "should raise an exception if the source is not set but we are installing" do + status = double("Status", :stdout => "", :exitstatus => 1, :format_for_exception => "") @new_resource = Chef::Resource::Package.new("samba.base") @provider = Chef::Provider::Package::Aix.new(@new_resource, @run_context) - allow(@provider).to receive(:popen4).and_return(@status) + allow(@provider).to receive(:shell_out).and_return(status) expect { @provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package) end it "should raise an exception if installp/lslpp fails to run" do - @status = double("Status", :exitstatus => -1) - allow(@provider).to receive(:popen4).and_return(@status) + status = double(:stdout => "", :exitstatus => -1, :format_for_exception => "") + allow(@provider).to receive(:shell_out).and_return(status) expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Package) end it "should return a current resource with a nil version if the package is not found" do - @stdout = StringIO.new - expect(@provider).to receive(:popen4).with("installp -L -d /tmp/samba.base").and_return(@status) - expect(@provider).to receive(:popen4).with("lslpp -lcq samba.base").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + status = double(:stdout => "", :exitstatus => 0) + expect(@provider).to receive(:shell_out).with("installp -L -d /tmp/samba.base").and_return(status) + expect(@provider).to receive(:shell_out).with("lslpp -lcq samba.base").and_return(status) @provider.load_current_resource expect(@provider.current_resource.version).to be_nil end @@ -104,19 +105,19 @@ describe Chef::Provider::Package::Aix do describe "candidate_version" do it "should return the candidate_version variable if already setup" do @provider.candidate_version = "3.3.12.0" - expect(@provider).not_to receive(:popen4) + expect(@provider).not_to receive(:shell_out ) @provider.candidate_version end it "should lookup the candidate_version if the variable is not already set" do - @status = double("Status", :exitstatus => 0) - expect(@provider).to receive(:popen4).and_return(@status) + status = double(:stdout => "", :exitstatus => 0) + expect(@provider).to receive(:shell_out).and_return(status) @provider.candidate_version end it "should throw and exception if the exitstatus is not 0" do - @status = double("Status", :exitstatus => 1) - allow(@provider).to receive(:popen4).and_return(@status) + @status = double(:stdout => "", :exitstatus => 1, :format_for_exception => "") + allow(@provider).to receive(:shell_out).and_return(@status) expect { @provider.candidate_version }.to raise_error(Chef::Exceptions::Package) end diff --git a/spec/unit/provider/package/dpkg_spec.rb b/spec/unit/provider/package/dpkg_spec.rb index 154809f88c..c838306c35 100644 --- a/spec/unit/provider/package/dpkg_spec.rb +++ b/spec/unit/provider/package/dpkg_spec.rb @@ -28,12 +28,8 @@ describe Chef::Provider::Package::Dpkg do @provider = Chef::Provider::Package::Dpkg.new(@new_resource, @run_context) - @stdin = StringIO.new - @stdout = StringIO.new - @status = double("Status", :exitstatus => 0) - @stderr = StringIO.new - @pid = double("PID") - allow(@provider).to receive(:popen4).and_return(@status) + @status = double(:stdout => "", :exitstatus => 0) + allow(@provider).to receive(:shell_out).and_return(@status) allow(::File).to receive(:exists?).and_return(true) end @@ -54,8 +50,8 @@ describe Chef::Provider::Package::Dpkg do describe 'gets the source package version from dpkg-deb' do def check_version(version) - @stdout = StringIO.new("wget\t#{version}") - allow(@provider).to receive(:popen4).with("dpkg-deb -W #{@new_resource.source}").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @status = double(:stdout => "wget\t#{version}", :exitstatus => 0) + allow(@provider).to receive(:shell_out).with("dpkg-deb -W #{@new_resource.source}").and_return(@status) @provider.load_current_resource expect(@provider.current_resource.package_name).to eq("wget") expect(@new_resource.version).to eq(version) @@ -79,8 +75,9 @@ describe Chef::Provider::Package::Dpkg do end it "gets the source package name from dpkg-deb correctly when the package name has `-', `+' or `.' characters" do - @stdout = StringIO.new("f.o.o-pkg++2\t1.11.4-1ubuntu1") - allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + stdout = "f.o.o-pkg++2\t1.11.4-1ubuntu1" + status = double(:stdout => stdout, :exitstatus => 1) + allow(@provider).to receive(:shell_out).and_return(status) @provider.load_current_resource expect(@provider.current_resource.package_name).to eq("f.o.o-pkg++2") end @@ -94,7 +91,7 @@ describe Chef::Provider::Package::Dpkg do end it "should return the current version installed if found by dpkg" do - @stdout = StringIO.new(<<-DPKG_S) + stdout = <<-DPKG_S Package: wget Status: install ok installed Priority: important @@ -107,15 +104,16 @@ Config-Version: 1.11.4-1ubuntu1 Depends: libc6 (>= 2.8~20080505), libssl0.9.8 (>= 0.9.8f-5) Conflicts: wget-ssl DPKG_S - allow(@provider).to receive(:popen4).with("dpkg -s wget").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + status = double(:stdout => stdout, :exitstatus => 1) + allow(@provider).to receive(:shell_out).with("dpkg -s wget").and_return(status) @provider.load_current_resource expect(@provider.current_resource.version).to eq("1.11.4-1ubuntu1") end it "should raise an exception if dpkg fails to run" do - @status = double("Status", :exitstatus => -1) - allow(@provider).to receive(:popen4).and_return(@status) + status = double(:stdout => "", :exitstatus => -1) + allow(@provider).to receive(:shell_out).and_return(status) expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Package) end end diff --git a/spec/unit/provider/package/macports_spec.rb b/spec/unit/provider/package/macports_spec.rb index 23a8233c66..9822fb3928 100644 --- a/spec/unit/provider/package/macports_spec.rb +++ b/spec/unit/provider/package/macports_spec.rb @@ -29,11 +29,11 @@ describe Chef::Provider::Package::Macports do @provider = Chef::Provider::Package::Macports.new(@new_resource, @run_context) allow(Chef::Resource::Package).to receive(:new).and_return(@current_resource) - @status = double("Status", :exitstatus => 0) - @stdin = StringIO.new - @stdout = StringIO.new - @stderr = StringIO.new - @pid = 2342 + # @status = double(:stdout => "", :exitstatus => 0) + # @stdin = StringIO.new + # @stdout = StringIO.new + # @stderr = StringIO.new + # @pid = 2342 end describe "load_current_resource" do @@ -70,33 +70,33 @@ describe Chef::Provider::Package::Macports do describe "current_installed_version" do it "should return the current version if the package is installed" do - expect(@stdout).to receive(:read).and_return(<<EOF + stdout = <<EOF The following ports are currently installed: openssl @0.9.8k_0 (active) EOF - ) - expect(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + status = double(:stdout => stdout, :exitstatus => 0) + expect(@provider).to receive(:shell_out).and_return(status) expect(@provider.current_installed_version).to eq("0.9.8k_0") end it "should return nil if a package is not currently installed" do - expect(@stdout).to receive(:read).and_return(" \n") - expect(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + status = double(:stdout => " \n", :exitstatus => 0) + expect(@provider).to receive(:shell_out).and_return(status) expect(@provider.current_installed_version).to be_nil end end describe "macports_candidate_version" do it "should return the latest available version of a given package" do - expect(@stdout).to receive(:read).and_return("version: 4.2.7\n") - expect(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + status = double(:stdout => "version: 4.2.7\n", :exitstatus => 0) + expect(@provider).to receive(:shell_out).and_return(status) expect(@provider.macports_candidate_version).to eq("4.2.7") end it "should return nil if there is no version for a given package" do - expect(@stdout).to receive(:read).and_return("Error: port fadsfadsfads not found\n") - expect(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + status = double(:stdout => "Error: port fadsfadsfads not found\n", :exitstatus => 0) + expect(@provider).to receive(:shell_out).and_return(status) expect(@provider.macports_candidate_version).to be_nil end end diff --git a/spec/unit/provider/package/pacman_spec.rb b/spec/unit/provider/package/pacman_spec.rb index 9fa5f9667c..3b8848c41b 100644 --- a/spec/unit/provider/package/pacman_spec.rb +++ b/spec/unit/provider/package/pacman_spec.rb @@ -26,10 +26,11 @@ describe Chef::Provider::Package::Pacman do @new_resource = Chef::Resource::Package.new("nano") @current_resource = Chef::Resource::Package.new("nano") - @status = double("Status", :exitstatus => 0) + @status = double(:stdout => "", :exitstatus => 0) @provider = Chef::Provider::Package::Pacman.new(@new_resource, @run_context) allow(Chef::Resource::Package).to receive(:new).and_return(@current_resource) - allow(@provider).to receive(:popen4).and_return(@status) + + allow(@provider).to receive(:shell_out).and_return(@status) @stdin = StringIO.new @stdout = StringIO.new(<<-ERR) error: package "nano" not found @@ -50,24 +51,23 @@ ERR end it "should run pacman query with the package name" do - expect(@provider).to receive(:popen4).with("pacman -Qi #{@new_resource.package_name}").and_return(@status) + expect(@provider).to receive(:shell_out).with("pacman -Qi #{@new_resource.package_name}").and_return(@status) @provider.load_current_resource end it "should read stdout on pacman" do - allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) - expect(@stdout).to receive(:each).and_return(true) + allow(@provider).to receive(:shell_out).and_return(@status) @provider.load_current_resource end it "should set the installed version to nil on the current resource if pacman installed version not exists" do - allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + allow(@provider).to receive(:shell_out).and_return(@status) expect(@current_resource).to receive(:version).with(nil).and_return(true) @provider.load_current_resource end it "should set the installed version if pacman has one" do - @stdout = StringIO.new(<<-PACMAN) + stdout = <<-PACMAN Name : nano Version : 2.2.2-1 URL : http://www.nano-editor.org @@ -88,14 +88,16 @@ Install Reason : Explicitly installed Install Script : Yes Description : Pico editor clone with enhancements PACMAN - allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + + status = double(:stdout => stdout, :exitstatus => 0) + allow(@provider).to receive(:shell_out).and_return(status) @provider.load_current_resource expect(@current_resource.version).to eq("2.2.2-1") end it "should set the candidate version if pacman has one" do - allow(@stdout).to receive(:each).and_yield("core nano 2.2.3-1") - allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + status = double(:stdout => "core nano 2.2.3-1", :exitstatus => 0) + allow(@provider).to receive(:shell_out).and_return(status) @provider.load_current_resource expect(@provider.candidate_version).to eql("2.2.3-1") end @@ -119,10 +121,10 @@ Include = /etc/pacman.d/mirrorlist Include = /etc/pacman.d/mirrorlist PACMAN_CONF + status = double(:stdout => "customrepo nano 1.2.3-4", :exitstatus => 0) allow(::File).to receive(:exists?).with("/etc/pacman.conf").and_return(true) allow(::File).to receive(:read).with("/etc/pacman.conf").and_return(@pacman_conf) - allow(@stdout).to receive(:each).and_yield("customrepo nano 1.2.3-4") - allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + allow(@provider).to receive(:shell_out).and_return(status) @provider.load_current_resource expect(@provider.candidate_version).to eql("1.2.3-4") @@ -139,8 +141,7 @@ PACMAN_CONF end it "should raise an exception if pacman does not return a candidate version" do - allow(@stdout).to receive(:each).and_yield("") - allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + allow(@provider).to receive(:shell_out).and_return(@status) expect { @provider.candidate_version }.to raise_error(Chef::Exceptions::Package) end diff --git a/spec/unit/provider/package/portage_spec.rb b/spec/unit/provider/package/portage_spec.rb index f83eda45de..55743dbeaf 100644 --- a/spec/unit/provider/package/portage_spec.rb +++ b/spec/unit/provider/package/portage_spec.rb @@ -102,13 +102,13 @@ describe Chef::Provider::Package::Portage, "load_current_resource" do describe Chef::Provider::Package::Portage, "candidate_version" do it "should return the candidate_version variable if already set" do @provider.candidate_version = "1.0.0" - expect(@provider).not_to receive(:popen4) + expect(@provider).not_to receive(:shell_out) @provider.candidate_version end it "should throw an exception if the exitstatus is not 0" do - @status = double("Status", :exitstatus => 1) - allow(@provider).to receive(:popen4).and_return(@status) + status = double(:stdout => "", :exitstatus => 1) + allow(@provider).to receive(:shell_out).and_return(status) expect { @provider.candidate_version }.to raise_error(Chef::Exceptions::Package) end @@ -143,8 +143,8 @@ Searching... License: GPL-2 EOF - @status = double("Status", :exitstatus => 0) - expect(@provider).to receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status) + status = double(:stdout => output, :exitstatus => 0) + expect(@provider).to receive(:shell_out).and_return(status) expect(@provider.candidate_version).to eq("1.6.0.6") end @@ -179,9 +179,9 @@ Searching... License: GPL-2 EOF - @status = double("Status", :exitstatus => 0) + status = double(:stdout => output, :exitstatus => 0) @provider = Chef::Provider::Package::Portage.new(@new_resource_without_category, @run_context) - expect(@provider).to receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status) + expect(@provider).to receive(:shell_out).and_return(status) expect(@provider.candidate_version).to eq("1.6.0.6") end @@ -224,9 +224,9 @@ Searching... License: GPL-2 EOF - @status = double("Status", :exitstatus => 0) + status = double(:stdout => output, :exitstatus => 0) @provider = Chef::Provider::Package::Portage.new(@new_resource_without_category, @run_context) - expect(@provider).to receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status) + expect(@provider).to receive(:shell_out).and_return(status) expect { @provider.candidate_version }.to raise_error(Chef::Exceptions::Package) end @@ -269,9 +269,9 @@ Searching... License: GPL-2 EOF - @status = double("Status", :exitstatus => 0) + status = double(:stdout => output, :exitstatus => 0) @provider = Chef::Provider::Package::Portage.new(@new_resource, @run_context) - expect(@provider).to receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status) + expect(@provider).to receive(:shell_out).and_return(status) expect(@provider.candidate_version).to eq("1.6.0.6") end end diff --git a/spec/unit/provider/package/solaris_spec.rb b/spec/unit/provider/package/solaris_spec.rb index 332fa9db1a..c348d665e8 100644 --- a/spec/unit/provider/package/solaris_spec.rb +++ b/spec/unit/provider/package/solaris_spec.rb @@ -46,23 +46,23 @@ INSTDATE: Nov 04 2009 01:02 HOTLINE: Please contact your local service provider PKGINFO - @status = double("Status", :exitstatus => 0) + @status = double("Status",:stdout => "", :exitstatus => 0) end it "should create a current resource with the name of new_resource" do - allow(@provider).to receive(:popen4).and_return(@status) + allow(@provider).to receive(:shell_out).and_return(@status) @provider.load_current_resource expect(@provider.current_resource.name).to eq("SUNWbash") end it "should set the current reource package name to the new resource package name" do - allow(@provider).to receive(:popen4).and_return(@status) + allow(@provider).to receive(:shell_out).and_return(@status) @provider.load_current_resource expect(@provider.current_resource.package_name).to eq("SUNWbash") end it "should raise an exception if a source is supplied but not found" do - allow(@provider).to receive(:popen4).and_return(@status) + allow(@provider).to receive(:shell_out).and_return(@status) allow(::File).to receive(:exists?).and_return(false) @provider.load_current_resource @provider.define_resource_requirements @@ -70,10 +70,9 @@ PKGINFO end it "should get the source package version from pkginfo if provided" do - @stdout = StringIO.new(@pkginfo) - @stdin, @stderr = StringIO.new, StringIO.new - expect(@provider).to receive(:popen4).with("pkginfo -l -d /tmp/bash.pkg SUNWbash").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) - expect(@provider).to receive(:popen4).with("pkginfo -l SUNWbash").and_return(@status) + status = double(:stdout => @pkginfo, :exitstatus => 0) + expect(@provider).to receive(:shell_out).with("pkginfo -l -d /tmp/bash.pkg SUNWbash").and_return(status) + expect(@provider).to receive(:shell_out).with("pkginfo -l SUNWbash").and_return(@status) @provider.load_current_resource expect(@provider.current_resource.package_name).to eq("SUNWbash") @@ -81,10 +80,9 @@ PKGINFO end it "should return the current version installed if found by pkginfo" do - @stdout = StringIO.new(@pkginfo) - @stdin, @stderr = StringIO.new, StringIO.new - expect(@provider).to receive(:popen4).with("pkginfo -l -d /tmp/bash.pkg SUNWbash").and_return(@status) - expect(@provider).to receive(:popen4).with("pkginfo -l SUNWbash").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + status = double(:stdout => @pkginfo, :exitstatus => 0) + expect(@provider).to receive(:shell_out).with("pkginfo -l -d /tmp/bash.pkg SUNWbash").and_return(@status) + expect(@provider).to receive(:shell_out).with("pkginfo -l SUNWbash").and_return(status) @provider.load_current_resource expect(@provider.current_resource.version).to eq("11.10.0,REV=2005.01.08.05.16") end @@ -92,20 +90,19 @@ PKGINFO it "should raise an exception if the source is not set but we are installing" do @new_resource = Chef::Resource::Package.new("SUNWbash") @provider = Chef::Provider::Package::Solaris.new(@new_resource, @run_context) - allow(@provider).to receive(:popen4).and_return(@status) + allow(@provider).to receive(:shell_out).and_return(@status) expect { @provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package) end it "should raise an exception if pkginfo fails to run" do - @status = double("Status", :exitstatus => -1) - allow(@provider).to receive(:popen4).and_return(@status) + status = double(:stdout => "", :exitstatus => -1) + allow(@provider).to receive(:shell_out).and_return(status) expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Package) end it "should return a current resource with a nil version if the package is not found" do - @stdout = StringIO.new - expect(@provider).to receive(:popen4).with("pkginfo -l -d /tmp/bash.pkg SUNWbash").and_return(@status) - expect(@provider).to receive(:popen4).with("pkginfo -l SUNWbash").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect(@provider).to receive(:shell_out).with("pkginfo -l -d /tmp/bash.pkg SUNWbash").and_return(@status) + expect(@provider).to receive(:shell_out).with("pkginfo -l SUNWbash").and_return(@status) @provider.load_current_resource expect(@provider.current_resource.version).to be_nil end @@ -114,20 +111,20 @@ PKGINFO describe "candidate_version" do it "should return the candidate_version variable if already setup" do @provider.candidate_version = "11.10.0,REV=2005.01.08.05.16" - expect(@provider).not_to receive(:popen4) + expect(@provider).not_to receive(:shell_out) @provider.candidate_version end it "should lookup the candidate_version if the variable is not already set" do - @status = double("Status", :exitstatus => 0) - allow(@provider).to receive(:popen4).and_return(@status) - expect(@provider).to receive(:popen4) + status = double(:stdout => "", :exitstatus => 0) + allow(@provider).to receive(:shell_out).and_return(status) + expect(@provider).to receive(:shell_out) @provider.candidate_version end it "should throw and exception if the exitstatus is not 0" do - @status = double("Status", :exitstatus => 1) - allow(@provider).to receive(:popen4).and_return(@status) + status = double(:stdout => "", :exitstatus => 1) + allow(@provider).to receive(:shell_out).and_return(status) expect { @provider.candidate_version }.to raise_error(Chef::Exceptions::Package) end diff --git a/spec/unit/provider/package/zypper_spec.rb b/spec/unit/provider/package/zypper_spec.rb index 17d99640e6..706ad722dd 100644 --- a/spec/unit/provider/package/zypper_spec.rb +++ b/spec/unit/provider/package/zypper_spec.rb @@ -27,14 +27,10 @@ describe Chef::Provider::Package::Zypper do @current_resource = Chef::Resource::Package.new("cups") - @status = double("Status", :exitstatus => 0) - @provider = Chef::Provider::Package::Zypper.new(@new_resource, @run_context) allow(Chef::Resource::Package).to receive(:new).and_return(@current_resource) - allow(@provider).to receive(:popen4).and_return(@status) - @stderr = StringIO.new - @stdout = StringIO.new - @pid = double("PID") + @status = double(:stdout => "\n", :exitstatus => 0) + allow(@provider).to receive(:shell_out).and_return(@status) allow(@provider).to receive(:`).and_return("2.0") end @@ -50,27 +46,28 @@ describe Chef::Provider::Package::Zypper do end it "should run zypper info with the package name" do - expect(@provider).to receive(:popen4).with("zypper --non-interactive info #{@new_resource.package_name}").and_return(@status) + expect(@provider).to receive(:shell_out).with("zypper --non-interactive info #{@new_resource.package_name}").and_return(@status) @provider.load_current_resource end it "should set the installed version to nil on the current resource if zypper info installed version is (none)" do - allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + allow(@provider).to receive(:shell_out).and_return(@status) expect(@current_resource).to receive(:version).with(nil).and_return(true) @provider.load_current_resource end it "should set the installed version if zypper info has one" do - @stdout = StringIO.new("Version: 1.0\nInstalled: Yes\n") - allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + status = double(:stdout => "Version: 1.0\nInstalled: Yes\n", :exitstatus => 0) + + allow(@provider).to receive(:shell_out).and_return(status) expect(@current_resource).to receive(:version).with("1.0").and_return(true) @provider.load_current_resource end it "should set the candidate version if zypper info has one" do - @stdout = StringIO.new("Version: 1.0\nInstalled: No\nStatus: out-of-date (version 0.9 installed)") + status = double(:stdout => "Version: 1.0\nInstalled: No\nStatus: out-of-date (version 0.9 installed)", :exitstatus => 0) - allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + allow(@provider).to receive(:shell_out).and_return(status) @provider.load_current_resource expect(@provider.candidate_version).to eql("1.0") end |