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.rb67
1 files changed, 67 insertions, 0 deletions
diff --git a/spec/unit/provider/package/zypper_spec.rb b/spec/unit/provider/package/zypper_spec.rb
index 3f172dc370..819278a795 100644
--- a/spec/unit/provider/package/zypper_spec.rb
+++ b/spec/unit/provider/package/zypper_spec.rb
@@ -267,6 +267,40 @@ describe Chef::Provider::Package::Zypper do
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!(
@@ -290,6 +324,39 @@ describe Chef::Provider::Package::Zypper do
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!(