Commit b512aaee authored by Bryan McLellan's avatar Bryan McLellan
Browse files

Merge branch 'CHEF-2129' into 0.9-stable

parents b67e8983 838ef46f
......@@ -84,9 +84,18 @@ class Chef
Chef::Log.debug("zypper current resource #{@current_resource}")
@current_resource
end
#Gets the zypper Version from command output (Returns Floating Point number)
def zypper_version()
`zypper -V 2>&1`.scan(/\d+/).join(".").to_f
end
def install_package(name, version)
if version
if zypper_version < 1.0
run_command(
:command => "zypper install -y #{name}"
)
elsif version
run_command(
:command => "zypper -n --no-gpg-checks install -l #{name}=#{version}"
)
......@@ -98,7 +107,11 @@ class Chef
end
def upgrade_package(name, version)
if version
if zypper_version < 1.0
run_command(
:command => "zypper install -y #{name}"
)
elsif version
run_command(
:command => "zypper -n --no-gpg-checks install -l #{name}=#{version}"
)
......@@ -110,7 +123,11 @@ class Chef
end
def remove_package(name, version)
if version
if zypper_version < 1.0
run_command(
:command => "zypper remove -y #{name}"
)
elsif version
run_command(
:command => "zypper -n --no-gpg-checks remove #{name}=#{version}"
)
......
......@@ -31,9 +31,10 @@ describe Chef::Provider::Package::Zypper do
@provider = Chef::Provider::Package::Zypper.new(@new_resource, @run_context)
Chef::Resource::Package.stub!(:new).and_return(@current_resource)
@provider.stub!(:popen4).and_return(@status)
@stderr = mock("STDERR", :null_object => true)
@stdout = mock("STDERR", :null_object => true)
@pid = mock("PID", :null_object => true)
@stderr = StringIO.new
@stdout = StringIO.new
@pid = mock("PID")
@provider.stub!(:`).and_return("2.0")
end
describe "when loading the current package state" do
......@@ -89,14 +90,12 @@ describe Chef::Provider::Package::Zypper do
end
describe "install_package" do
it "should run zypper install with the package name and version" do
@provider.should_receive(:run_command).with({
:command => "zypper -n --no-gpg-checks install -l emacs=1.0",
})
@provider.install_package("emacs", "1.0")
end
end
describe "upgrade_package" do
......@@ -123,4 +122,37 @@ describe Chef::Provider::Package::Zypper do
@provider.purge_package("emacs", "1.0")
end
end
describe "on an older zypper" do
before(:each) do
@provider.stub!(:`).and_return("0.11.6")
end
describe "install_package" do
it "should run zypper install with the package name and version" do
@provider.should_receive(:run_command).with({
:command => "zypper install -y emacs"
})
@provider.install_package("emacs", "1.0")
end
end
describe "upgrade_package" do
it "should run zypper update with the package name and version" do
@provider.should_receive(:run_command).with({
:command => "zypper install -y emacs"
})
@provider.upgrade_package("emacs", "1.0")
end
end
describe "remove_package" do
it "should run zypper remove with the package name" do
@provider.should_receive(:run_command).with({
:command => "zypper remove -y emacs"
})
@provider.remove_package("emacs", "1.0")
end
end
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment