summaryrefslogtreecommitdiff
path: root/spec/unit/provider/package/apt_spec.rb
diff options
context:
space:
mode:
authorClaire McQuin <mcquin@users.noreply.github.com>2014-06-10 16:16:31 -0700
committerClaire McQuin <mcquin@users.noreply.github.com>2014-06-10 16:16:31 -0700
commit3ca542e7a2e6eab4a19c13e1938d154aa22cb44d (patch)
tree8f08d82d7b26841e6da516ac6b88764d2c875f9a /spec/unit/provider/package/apt_spec.rb
parente5cbd0d532a393b10f073bccd1b5045b9082b9ab (diff)
parente9cfad2fd5c2c659e51fa7ef07906e1a80af7236 (diff)
downloadchef-3ca542e7a2e6eab4a19c13e1938d154aa22cb44d.tar.gz
Merge pull request #1462 from pdf/CHEF-5168
[CHEF-5168] Apt Package provider times out
Diffstat (limited to 'spec/unit/provider/package/apt_spec.rb')
-rw-r--r--spec/unit/provider/package/apt_spec.rb130
1 files changed, 87 insertions, 43 deletions
diff --git a/spec/unit/provider/package/apt_spec.rb b/spec/unit/provider/package/apt_spec.rb
index e5a3e4c689..acd772f279 100644
--- a/spec/unit/provider/package/apt_spec.rb
+++ b/spec/unit/provider/package/apt_spec.rb
@@ -24,7 +24,7 @@ describe Chef::Provider::Package::Apt do
@node = Chef::Node.new
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, {}, @events)
- @new_resource = Chef::Resource::Package.new("irssi", @run_context)
+ @new_resource = Chef::Resource::AptPackage.new("irssi", @run_context)
@status = double("Status", :exitstatus => 0)
@provider = Chef::Provider::Package::Apt.new(@new_resource, @run_context)
@@ -39,16 +39,20 @@ irssi:
PKG_STATUS
@stderr = ""
@shell_out = OpenStruct.new(:stdout => @stdout,:stdin => @stdin,:stderr => @stderr,:status => @status,:exitstatus => 0)
+ @timeout = 900
end
describe "when loading current resource" do
it "should create a current resource with the name of the new_resource" do
- @provider.should_receive(:shell_out!).with("apt-cache policy #{@new_resource.package_name}").and_return(@shell_out)
+ @provider.should_receive(:shell_out!).with(
+ "apt-cache policy #{@new_resource.package_name}",
+ :timeout => @timeout
+ ).and_return(@shell_out)
@provider.load_current_resource
current_resource = @provider.current_resource
- current_resource.should be_a(Chef::Resource::Package)
+ current_resource.should be_a(Chef::Resource::AptPackage)
current_resource.name.should == "irssi"
current_resource.package_name.should == "irssi"
current_resource.version.should be_nil
@@ -84,7 +88,10 @@ libmysqlclient15-dev:
Version table:
VPKG_STDOUT
virtual_package = double(:stdout => virtual_package_out,:exitstatus => 0)
- @provider.should_receive(:shell_out!).with("apt-cache policy libmysqlclient15-dev").and_return(virtual_package)
+ @provider.should_receive(:shell_out!).with(
+ "apt-cache policy libmysqlclient15-dev",
+ :timeout => @timeout
+ ).and_return(virtual_package)
showpkg_out =<<-SHOWPKG_STDOUT
Package: libmysqlclient15-dev
Versions:
@@ -104,7 +111,10 @@ libmysqlclient-dev 5.1.41-3ubuntu12.10
libmysqlclient-dev 5.1.41-3ubuntu12
SHOWPKG_STDOUT
showpkg = double(:stdout => showpkg_out,:exitstatus => 0)
- @provider.should_receive(:shell_out!).with("apt-cache showpkg libmysqlclient15-dev").and_return(showpkg)
+ @provider.should_receive(:shell_out!).with(
+ "apt-cache showpkg libmysqlclient15-dev",
+ :timeout => @timeout
+ ).and_return(showpkg)
real_package_out=<<-RPKG_STDOUT
libmysqlclient-dev:
Installed: 5.1.41-3ubuntu12.10
@@ -119,7 +129,10 @@ libmysqlclient-dev:
500 http://us.archive.ubuntu.com/ubuntu/ lucid/main Packages
RPKG_STDOUT
real_package = double(:stdout => real_package_out,:exitstatus => 0)
- @provider.should_receive(:shell_out!).with("apt-cache policy libmysqlclient-dev").and_return(real_package)
+ @provider.should_receive(:shell_out!).with(
+ "apt-cache policy libmysqlclient-dev",
+ :timeout => @timeout
+ ).and_return(real_package)
@provider.load_current_resource
end
@@ -132,7 +145,10 @@ mp3-decoder:
Version table:
VPKG_STDOUT
virtual_package = double(:stdout => virtual_package_out,:exitstatus => 0)
- @provider.should_receive(:shell_out!).with("apt-cache policy mp3-decoder").and_return(virtual_package)
+ @provider.should_receive(:shell_out!).with(
+ "apt-cache policy mp3-decoder",
+ :timeout => @timeout
+ ).and_return(virtual_package)
showpkg_out=<<-SHOWPKG_STDOUT
Package: mp3-decoder
Versions:
@@ -155,7 +171,10 @@ mpg321 0.2.10.6
mpg123 1.12.1-0ubuntu1
SHOWPKG_STDOUT
showpkg = double(:stdout => showpkg_out,:exitstatus => 0)
- @provider.should_receive(:shell_out!).with("apt-cache showpkg mp3-decoder").and_return(showpkg)
+ @provider.should_receive(:shell_out!).with(
+ "apt-cache showpkg mp3-decoder",
+ :timeout => @timeout
+ ).and_return(showpkg)
lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package)
end
@@ -165,7 +184,10 @@ SHOWPKG_STDOUT
@new_resource.stub(:default_release).and_return("lenny-backports")
@new_resource.stub(:provider).and_return("Chef::Provider::Package::Apt")
- @provider.should_receive(:shell_out!).with("apt-cache -o APT::Default-Release=lenny-backports policy irssi").and_return(@shell_out)
+ @provider.should_receive(:shell_out!).with(
+ "apt-cache -o APT::Default-Release=lenny-backports policy irssi",
+ :timeout => @timeout
+ ).and_return(@shell_out)
@provider.load_current_resource
end
@@ -179,22 +201,26 @@ SHOWPKG_STDOUT
context "after loading the current resource" do
before do
- @current_resource = Chef::Resource::Package.new("irssi", @run_context)
+ @current_resource = Chef::Resource::AptPackage.new("irssi", @run_context)
@provider.current_resource = @current_resource
end
describe "install_package" do
it "should run apt-get install with the package name and version" do
- @provider.should_receive(:shell_out!).
- with("apt-get -q -y install irssi=0.8.12-7",
- :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil})
+ @provider.should_receive(:shell_out!). with(
+ "apt-get -q -y install irssi=0.8.12-7",
+ :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil},
+ :timeout => @timeout
+ )
@provider.install_package("irssi", "0.8.12-7")
end
it "should run apt-get install with the package name and version and options if specified" do
- @provider.should_receive(:shell_out!).
- with("apt-get -q -y --force-yes install irssi=0.8.12-7",
- :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil })
+ @provider.should_receive(:shell_out!).with(
+ "apt-get -q -y --force-yes install irssi=0.8.12-7",
+ :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil },
+ :timeout => @timeout
+ )
@new_resource.options("--force-yes")
@provider.install_package("irssi", "0.8.12-7")
end
@@ -206,9 +232,11 @@ SHOWPKG_STDOUT
@provider.new_resource = @new_resource
- @provider.should_receive(:shell_out!).
- with("apt-get -q -y -o APT::Default-Release=lenny-backports install irssi=0.8.12-7",
- :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil })
+ @provider.should_receive(:shell_out!).with(
+ "apt-get -q -y -o APT::Default-Release=lenny-backports install irssi=0.8.12-7",
+ :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil },
+ :timeout => @timeout
+ )
@provider.install_package("irssi", "0.8.12-7")
end
@@ -225,16 +253,20 @@ SHOWPKG_STDOUT
describe Chef::Provider::Package::Apt, "remove_package" do
it "should run apt-get remove with the package name" do
- @provider.should_receive(:shell_out!).
- with("apt-get -q -y remove irssi",
- :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil})
+ @provider.should_receive(:shell_out!).with(
+ "apt-get -q -y remove irssi",
+ :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil},
+ :timeout => @timeout
+ )
@provider.remove_package("irssi", "0.8.12-7")
end
it "should run apt-get remove with the package name and options if specified" do
- @provider.should_receive(:shell_out!).
- with("apt-get -q -y --force-yes remove irssi",
- :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil })
+ @provider.should_receive(:shell_out!).with(
+ "apt-get -q -y --force-yes remove irssi",
+ :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil },
+ :timeout => @timeout
+ )
@new_resource.options("--force-yes")
@provider.remove_package("irssi", "0.8.12-7")
@@ -244,16 +276,20 @@ SHOWPKG_STDOUT
describe "when purging a package" do
it "should run apt-get purge with the package name" do
- @provider.should_receive(:shell_out!).
- with("apt-get -q -y purge irssi",
- :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil })
+ @provider.should_receive(:shell_out!).with(
+ "apt-get -q -y purge irssi",
+ :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil },
+ :timeout => @timeout
+ )
@provider.purge_package("irssi", "0.8.12-7")
end
it "should run apt-get purge with the package name and options if specified" do
- @provider.should_receive(:shell_out!).
- with("apt-get -q -y --force-yes purge irssi",
- :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil })
+ @provider.should_receive(:shell_out!).with(
+ "apt-get -q -y --force-yes purge irssi",
+ :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil },
+ :timeout => @timeout
+ )
@new_resource.options("--force-yes")
@provider.purge_package("irssi", "0.8.12-7")
@@ -269,17 +305,21 @@ SHOWPKG_STDOUT
@provider.should_receive(:get_preseed_file).with("irssi", "0.8.12-7").and_return("/tmp/irssi-0.8.12-7.seed")
file = @provider.get_preseed_file("irssi", "0.8.12-7")
- @provider.should_receive(:shell_out!).
- with("debconf-set-selections /tmp/irssi-0.8.12-7.seed",
- :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil})
+ @provider.should_receive(:shell_out!).with(
+ "debconf-set-selections /tmp/irssi-0.8.12-7.seed",
+ :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil},
+ :timeout => @timeout
+ )
@provider.preseed_package(file)
end
it "should run debconf-set-selections on the preseed file if it has changed" do
- @provider.should_receive(:shell_out!).
- with("debconf-set-selections /tmp/irssi-0.8.12-7.seed",
- :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil})
+ @provider.should_receive(:shell_out!).with(
+ "debconf-set-selections /tmp/irssi-0.8.12-7.seed",
+ :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil},
+ :timeout => @timeout
+ )
file = @provider.get_preseed_file("irssi", "0.8.12-7")
@provider.preseed_package(file)
end
@@ -296,9 +336,11 @@ SHOWPKG_STDOUT
describe "when reconfiguring a package" do
it "should run dpkg-reconfigure package" do
- @provider.should_receive(:shell_out!).
- with("dpkg-reconfigure irssi",
- :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil })
+ @provider.should_receive(:shell_out!).with(
+ "dpkg-reconfigure irssi",
+ :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil },
+ :timeout => @timeout
+ )
@provider.reconfig_package("irssi", "0.8.12-7")
end
end
@@ -306,9 +348,11 @@ SHOWPKG_STDOUT
describe "when installing a virtual package" do
it "should install the package without specifying a version" do
@provider.is_virtual_package = true
- @provider.should_receive(:shell_out!).
- with("apt-get -q -y install libmysqlclient-dev",
- :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil })
+ @provider.should_receive(:shell_out!).with(
+ "apt-get -q -y install libmysqlclient-dev",
+ :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil },
+ :timeout => @timeout
+ )
@provider.install_package("libmysqlclient-dev", "not_a_real_version")
end
end