summaryrefslogtreecommitdiff
path: root/spec/unit/provider/package/zypper_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/provider/package/zypper_spec.rb')
-rw-r--r--spec/unit/provider/package/zypper_spec.rb273
1 files changed, 218 insertions, 55 deletions
diff --git a/spec/unit/provider/package/zypper_spec.rb b/spec/unit/provider/package/zypper_spec.rb
index df0a1da9a2..819278a795 100644
--- a/spec/unit/provider/package/zypper_spec.rb
+++ b/spec/unit/provider/package/zypper_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software, Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -38,14 +38,14 @@ describe Chef::Provider::Package::Zypper do
allow(provider).to receive(:`).and_return("2.0")
end
- def shell_out_expectation(command, options = nil)
- options ||= { timeout: 900 }
- expect(provider).to receive(:shell_out).with(command, options)
+ def shell_out_expectation(*command, **options)
+ options[:timeout] ||= 900
+ expect(provider).to receive(:shell_out).with(*command, **options)
end
- def shell_out_expectation!(command, options = nil)
- options ||= { timeout: 900 }
- expect(provider).to receive(:shell_out!).with(command, options)
+ def shell_out_expectation!(*command, **options)
+ options[:timeout] ||= 900
+ expect(provider).to receive(:shell_out!).with(*command, **options)
end
describe "when loading the current package state" do
@@ -61,7 +61,7 @@ describe Chef::Provider::Package::Zypper do
it "should run zypper info with the package name" do
shell_out_expectation!(
- "zypper --non-interactive info #{new_resource.package_name}"
+ "zypper", "--non-interactive", "info", new_resource.package_name
).and_return(status)
provider.load_current_resource
end
@@ -72,7 +72,7 @@ describe Chef::Provider::Package::Zypper do
provider.load_current_resource
end
- it "should set the installed version if zypper info has one" do
+ it "should set the installed version if zypper info has one (zypper version < 1.13.0)" do
status = double(:stdout => "Version: 1.0\nInstalled: Yes\n", :exitstatus => 0)
allow(provider).to receive(:shell_out!).and_return(status)
@@ -80,7 +80,23 @@ describe Chef::Provider::Package::Zypper do
provider.load_current_resource
end
- it "should set the candidate version if zypper info has one" do
+ it "should set the installed version if zypper info has one (zypper version >= 1.13.0)" do
+ 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 installed version if zypper info has one (zypper version >= 1.13.17)" do
+ status = double(:stdout => "Version : 1.0\nInstalled : Yes (automatically)\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 (zypper version < 1.13.0)" do
status = double(:stdout => "Version: 1.0\nInstalled: No\nStatus: out-of-date (version 0.9 installed)", :exitstatus => 0)
allow(provider).to receive(:shell_out!).and_return(status)
@@ -88,6 +104,14 @@ describe Chef::Provider::Package::Zypper do
expect(provider.candidate_version).to eql(["1.0"])
end
+ it "should set the candidate version if zypper info has one (zypper version >= 1.13.0)" do
+ status = double(:stdout => "Version : 1.0 \nInstalled : No \nStatus : out-of-date (version 0.9 installed)", :exitstatus => 0)
+
+ allow(provider).to receive(:shell_out!).and_return(status)
+ provider.load_current_resource
+ expect(provider.candidate_version).to eql(["1.0"])
+ end
+
it "should return the current resouce" do
expect(provider.load_current_resource).to eql(current_resource)
end
@@ -95,25 +119,47 @@ describe Chef::Provider::Package::Zypper do
describe "install_package" do
it "should run zypper install with the package name and version" do
- allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(true)
shell_out_expectation!(
- "zypper --non-interactive install --auto-agree-with-licenses emacs=1.0"
+ "zypper", "--non-interactive", "install", "--auto-agree-with-licenses", "emacs=1.0"
+ )
+ provider.install_package(["emacs"], ["1.0"])
+ end
+
+ it "should run zypper install with gpg checks" do
+ shell_out_expectation!(
+ "zypper", "--non-interactive", "install", "--auto-agree-with-licenses", "emacs=1.0"
+ )
+ provider.install_package(["emacs"], ["1.0"])
+ end
+
+ it "setting the property should disable gpg checks" do
+ new_resource.gpg_check false
+ shell_out_expectation!(
+ "zypper", "--non-interactive", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "emacs=1.0"
)
provider.install_package(["emacs"], ["1.0"])
end
- it "should run zypper install without gpg checks" do
- allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(false)
+
+ it "setting the config variable should disable gpg checks" do
+ Chef::Config[:zypper_check_gpg] = false
shell_out_expectation!(
- "zypper --non-interactive --no-gpg-checks install " + "--auto-agree-with-licenses emacs=1.0"
+ "zypper", "--non-interactive", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "emacs=1.0"
)
provider.install_package(["emacs"], ["1.0"])
end
- it "should warn about gpg checks on zypper install" do
- expect(Chef::Log).to receive(:warn).with(
- /All packages will be installed without gpg signature checks/
+
+ it "setting the property should allow downgrade" do
+ new_resource.allow_downgrade true
+ shell_out_expectation!(
+ "zypper", "--non-interactive", "install", "--auto-agree-with-licenses", "--oldpackage", "emacs=1.0"
)
+ provider.install_package(["emacs"], ["1.0"])
+ end
+
+ it "should add user provided options to the command" do
+ new_resource.options "--user-provided"
shell_out_expectation!(
- "zypper --non-interactive --no-gpg-checks install " + "--auto-agree-with-licenses emacs=1.0"
+ "zypper", "--non-interactive", "install", "--user-provided", "--auto-agree-with-licenses", "emacs=1.0"
)
provider.install_package(["emacs"], ["1.0"])
end
@@ -121,31 +167,29 @@ describe Chef::Provider::Package::Zypper do
describe "upgrade_package" do
it "should run zypper update with the package name and version" do
- allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(true)
shell_out_expectation!(
- "zypper --non-interactive install --auto-agree-with-licenses emacs=1.0"
+ "zypper", "--non-interactive", "install", "--auto-agree-with-licenses", "emacs=1.0"
)
provider.upgrade_package(["emacs"], ["1.0"])
end
- it "should run zypper update without gpg checks" do
- allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(false)
+ it "should run zypper update without gpg checks when setting the property" do
+ new_resource.gpg_check false
shell_out_expectation!(
- "zypper --non-interactive --no-gpg-checks install " + "--auto-agree-with-licenses emacs=1.0"
+ "zypper", "--non-interactive", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "emacs=1.0"
)
provider.upgrade_package(["emacs"], ["1.0"])
end
- it "should warn about gpg checks on zypper upgrade" do
- expect(Chef::Log).to receive(:warn).with(
- /All packages will be installed without gpg signature checks/
- )
+ it "should run zypper update without gpg checks when setting the config variable" do
+ Chef::Config[:zypper_check_gpg] = false
shell_out_expectation!(
- "zypper --non-interactive --no-gpg-checks install " + "--auto-agree-with-licenses emacs=1.0"
+ "zypper", "--non-interactive", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "emacs=1.0"
)
provider.upgrade_package(["emacs"], ["1.0"])
end
- it "should run zypper upgrade without gpg checks" do
+ it "should add user provided options to the command" do
+ new_resource.options "--user-provided"
shell_out_expectation!(
- "zypper --non-interactive --no-gpg-checks install " + "--auto-agree-with-licenses emacs=1.0"
+ "zypper", "--non-interactive", "install", "--user-provided", "--auto-agree-with-licenses", "emacs=1.0"
)
provider.upgrade_package(["emacs"], ["1.0"])
end
@@ -155,9 +199,8 @@ describe Chef::Provider::Package::Zypper do
context "when package version is not explicitly specified" do
it "should run zypper remove with the package name" do
- allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(true)
shell_out_expectation!(
- "zypper --non-interactive remove emacs"
+ "zypper", "--non-interactive", "remove", "emacs"
)
provider.remove_package(["emacs"], [nil])
end
@@ -165,25 +208,29 @@ describe Chef::Provider::Package::Zypper do
context "when package version is explicitly specified" do
it "should run zypper remove with the package name" do
- allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(true)
shell_out_expectation!(
- "zypper --non-interactive remove emacs=1.0"
+ "zypper", "--non-interactive", "remove", "emacs=1.0"
)
provider.remove_package(["emacs"], ["1.0"])
end
it "should run zypper remove without gpg checks" do
- allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(false)
+ new_resource.gpg_check false
shell_out_expectation!(
- "zypper --non-interactive --no-gpg-checks remove emacs=1.0"
+ "zypper", "--non-interactive", "--no-gpg-checks", "remove", "emacs=1.0"
)
provider.remove_package(["emacs"], ["1.0"])
end
- it "should warn about gpg checks on zypper remove" do
- expect(Chef::Log).to receive(:warn).with(
- /All packages will be installed without gpg signature checks/
+ it "should run zypper remove without gpg checks when the config is false" do
+ Chef::Config[:zypper_check_gpg] = false
+ shell_out_expectation!(
+ "zypper", "--non-interactive", "--no-gpg-checks", "remove", "emacs=1.0"
)
+ provider.remove_package(["emacs"], ["1.0"])
+ end
+ it "should add user provided options to the command" do
+ new_resource.options "--user-provided"
shell_out_expectation!(
- "zypper --non-interactive --no-gpg-checks remove emacs=1.0"
+ "zypper", "--non-interactive", "remove", "--user-provided", "emacs=1.0"
)
provider.remove_package(["emacs"], ["1.0"])
end
@@ -193,28 +240,146 @@ describe Chef::Provider::Package::Zypper do
describe "purge_package" do
it "should run remove with the name and version and --clean-deps" do
shell_out_expectation!(
- "zypper --non-interactive --no-gpg-checks remove --clean-deps emacs=1.0"
+ "zypper", "--non-interactive", "remove", "--clean-deps", "emacs=1.0"
)
provider.purge_package(["emacs"], ["1.0"])
end
it "should run zypper purge without gpg checks" do
- allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(false)
+ new_resource.gpg_check false
shell_out_expectation!(
- "zypper --non-interactive --no-gpg-checks remove --clean-deps emacs=1.0"
+ "zypper", "--non-interactive", "--no-gpg-checks", "remove", "--clean-deps", "emacs=1.0"
)
provider.purge_package(["emacs"], ["1.0"])
end
- it "should warn about gpg checks on zypper purge" do
- expect(Chef::Log).to receive(:warn).with(
- /All packages will be installed without gpg signature checks/
+ it "should run zypper purge without gpg checks when the config is false" do
+ Chef::Config[:zypper_check_gpg] = false
+ shell_out_expectation!(
+ "zypper", "--non-interactive", "--no-gpg-checks", "remove", "--clean-deps", "emacs=1.0"
)
+ provider.purge_package(["emacs"], ["1.0"])
+ end
+ it "should add user provided options to the command" do
+ new_resource.options "--user-provided"
shell_out_expectation!(
- "zypper --non-interactive --no-gpg-checks remove --clean-deps emacs=1.0"
+ "zypper", "--non-interactive", "remove", "--user-provided", "--clean-deps", "emacs=1.0"
)
provider.purge_package(["emacs"], ["1.0"])
end
end
+ describe "action_lock" do
+ it "should lock if the package is not already locked" do
+ prov = provider
+ allow(prov).to receive(:shell_out_compact_timeout!).with(
+ "zypper", "--non-interactive", "info", new_resource.package_name
+ ).and_return(status)
+ allow(prov).to receive(:shell_out_compact_timeout!).with(
+ "zypper", "locks"
+ ).and_return(instance_double(
+ Mixlib::ShellOut, stdout: "1 | somethingelse | package | (any)"
+ ))
+ expect(prov).to receive(:lock_package).with(["cups"], [nil])
+
+ prov.load_current_resource
+ prov.action_lock
+ end
+
+ it "should not lock if the package is already locked" do
+ prov = provider
+ allow(prov).to receive(:shell_out_compact_timeout!).with(
+ "zypper", "--non-interactive", "info", new_resource.package_name
+ ).and_return(status)
+ allow(prov).to receive(:shell_out_compact_timeout!).with(
+ "zypper", "locks"
+ ).and_return(instance_double(
+ Mixlib::ShellOut, stdout: "1 | cups | package | (any)"
+ ))
+ expect(prov).to_not receive(:lock_package)
+
+ prov.load_current_resource
+ prov.action_lock
+ end
+ end
+
+ describe "lock_package" do
+ it "should run zypper addlock with the package name" do
+ shell_out_expectation!(
+ "zypper", "--non-interactive", "addlock", "emacs"
+ )
+ provider.lock_package(["emacs"], [nil])
+ end
+ it "should run zypper addlock without gpg checks" do
+ new_resource.gpg_check false
+ shell_out_expectation!(
+ "zypper", "--non-interactive", "--no-gpg-checks", "addlock", "emacs"
+ )
+ provider.lock_package(["emacs"], [nil])
+ end
+ it "should add user provided options to the command" do
+ new_resource.options "--user-provided"
+ shell_out_expectation!(
+ "zypper", "--non-interactive", "addlock", "--user-provided", "emacs"
+ )
+ provider.lock_package(["emacs"], [nil])
+ end
+ end
+
+ describe "action_unlock" do
+ it "should unlock if the package is not already unlocked" do
+ prov = provider
+ allow(prov).to receive(:shell_out_compact_timeout!).with(
+ "zypper", "--non-interactive", "info", new_resource.package_name
+ ).and_return(status)
+ allow(prov).to receive(:shell_out_compact_timeout!).with(
+ "zypper", "locks"
+ ).and_return(instance_double(
+ Mixlib::ShellOut, stdout: "1 | cups | package | (any)"
+ ))
+ expect(prov).to receive(:unlock_package).with(["cups"], [nil])
+
+ prov.load_current_resource
+ provider.action_unlock
+ end
+ it "should not unlock if the package is already unlocked" do
+ prov = provider
+ allow(prov).to receive(:shell_out_compact_timeout!).with(
+ "zypper", "--non-interactive", "info", new_resource.package_name
+ ).and_return(status)
+ allow(prov).to receive(:shell_out_compact_timeout!).with(
+ "zypper", "locks"
+ ).and_return(instance_double(
+ Mixlib::ShellOut, stdout: "1 | somethingelse | package | (any)"
+ ))
+ expect(prov).to_not receive(:unlock_package)
+
+ prov.load_current_resource
+ provider.action_unlock
+ end
+ end
+
+ describe "unlock_package" do
+ it "should run zypper removelock with the package name" do
+ shell_out_expectation!(
+ "zypper", "--non-interactive", "removelock", "emacs"
+ )
+ provider.unlock_package(["emacs"], [nil])
+ end
+ it "should run zypper removelock without gpg checks" do
+ new_resource.gpg_check false
+ shell_out_expectation!(
+ "zypper", "--non-interactive", "--no-gpg-checks", "removelock", "emacs"
+ )
+ provider.unlock_package(["emacs"], [nil])
+ end
+ it "should add user provided options to the command" do
+ new_resource.options "--user-provided"
+ shell_out_expectation!(
+ "zypper", "--non-interactive", "removelock", "--user-provided", "emacs"
+ )
+ provider.unlock_package(["emacs"], [nil])
+ end
+ end
+
describe "on an older zypper" do
before(:each) do
allow(provider).to receive(:`).and_return("0.11.6")
@@ -223,7 +388,7 @@ describe Chef::Provider::Package::Zypper do
describe "install_package" do
it "should run zypper install with the package name and version" do
shell_out_expectation!(
- "zypper --no-gpg-checks install --auto-agree-with-licenses -y emacs"
+ "zypper", "install", "--auto-agree-with-licenses", "-y", "emacs"
)
provider.install_package(["emacs"], ["1.0"])
end
@@ -232,7 +397,7 @@ describe Chef::Provider::Package::Zypper do
describe "upgrade_package" do
it "should run zypper update with the package name and version" do
shell_out_expectation!(
- "zypper --no-gpg-checks install --auto-agree-with-licenses -y emacs"
+ "zypper", "install", "--auto-agree-with-licenses", "-y", "emacs"
)
provider.upgrade_package(["emacs"], ["1.0"])
end
@@ -241,7 +406,7 @@ describe Chef::Provider::Package::Zypper do
describe "remove_package" do
it "should run zypper remove with the package name" do
shell_out_expectation!(
- "zypper --no-gpg-checks remove -y emacs"
+ "zypper", "remove", "-y", "emacs"
)
provider.remove_package(["emacs"], ["1.0"])
end
@@ -250,17 +415,15 @@ describe Chef::Provider::Package::Zypper do
describe "when installing multiple packages" do # https://github.com/chef/chef/issues/3570
it "should install an array of package names and versions" do
- allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(false)
shell_out_expectation!(
- "zypper --non-interactive --no-gpg-checks install " + "--auto-agree-with-licenses emacs=1.0 vim=2.0"
+ "zypper", "--non-interactive", "install", "--auto-agree-with-licenses", "emacs=1.0", "vim=2.0"
)
provider.install_package(%w{emacs vim}, ["1.0", "2.0"])
end
it "should remove an array of package names and versions" do
- allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(false)
shell_out_expectation!(
- "zypper --non-interactive --no-gpg-checks remove emacs=1.0 vim=2.0"
+ "zypper", "--non-interactive", "remove", "emacs=1.0", "vim=2.0"
)
provider.remove_package(%w{emacs vim}, ["1.0", "2.0"])
end