summaryrefslogtreecommitdiff
path: root/spec/unit/provider/package_spec.rb
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-02-19 15:17:05 -0800
committerJay Mundrawala <jdmundrawala@gmail.com>2015-02-19 15:17:05 -0800
commit864f9ac95063c7833235c8ed50dcb89653eda03f (patch)
tree93da186fd522bdfc5de6414d011f4c0dd49aeb40 /spec/unit/provider/package_spec.rb
parent194f49bdb7737e0591271ba95021997e90379c5d (diff)
parenta7f5c92960aedf8d5bfc71abbce430ab075e016a (diff)
downloadchef-864f9ac95063c7833235c8ed50dcb89653eda03f.tar.gz
Merge remote-tracking branch 'origin/master' into HEADjdm/merge-into-12-stable
* origin/master: (642 commits) Remove Chef 12 release notes Update Changelog for Chef 12.1.0 Chef 12.1.0.rc.0 Group spec needs to respond to shell_out fix dpkg regression fix Lint/BlockAlignment whitespaces fixes fix Lint/AmbiguousRegexpLiteral fix Lint/LiteralInCondition fix Lint/Loop style Make tests pass on Windows remove unreachable code Fix unit specs for PR #2934 dont raise exceptions in load_current_resource when checking current status update changelog fix typo in msi provider Added spec for #2914 fix virtual package logic in check_package_state use scalar pkg not array package convert is_virtual_package to hash ... Conflicts: .travis.yml CHANGELOG.md DOC_CHANGES.md RELEASE_NOTES.md appveyor.yml lib/chef/application.rb lib/chef/dsl/recipe.rb lib/chef/knife/bootstrap.rb lib/chef/knife/core/bootstrap_context.rb lib/chef/node/attribute.rb lib/chef/node/attribute_collections.rb lib/chef/node/immutable_collections.rb lib/chef/resource.rb lib/chef/run_context.rb lib/chef/version.rb spec/functional/dsl/reboot_pending_spec.rb spec/functional/event_loggers/windows_eventlog_spec.rb spec/functional/resource/link_spec.rb spec/support/platform_helpers.rb spec/unit/knife_spec.rb spec/unit/mixin/deep_merge_spec.rb spec/unit/mixin/shell_out_spec.rb spec/unit/node/attribute_spec.rb spec/unit/node_spec.rb spec/unit/provider/package/apt_spec.rb spec/unit/provider/service/systemd_service_spec.rb spec/unit/provider_resolver_spec.rb spec/unit/recipe_spec.rb spec/unit/resource/resource_notification_spec.rb spec/unit/run_context_spec.rb
Diffstat (limited to 'spec/unit/provider/package_spec.rb')
-rw-r--r--spec/unit/provider/package_spec.rb278
1 files changed, 276 insertions, 2 deletions
diff --git a/spec/unit/provider/package_spec.rb b/spec/unit/provider/package_spec.rb
index 3a42bcacf6..1633d18f9d 100644
--- a/spec/unit/provider/package_spec.rb
+++ b/spec/unit/provider/package_spec.rb
@@ -152,7 +152,7 @@ describe Chef::Provider::Package do
it "should print the word 'uninstalled' if there was no original version" do
allow(@current_resource).to receive(:version).and_return(nil)
- expect(Chef::Log).to receive(:info).with("package[emacs] upgraded from uninstalled to 1.0")
+ expect(Chef::Log).to receive(:info).with("package[emacs] upgraded emacs to 1.0")
@provider.run_action(:upgrade)
expect(@new_resource).to be_updated_by_last_action
end
@@ -376,7 +376,7 @@ describe Chef::Provider::Package do
end
it "should never back up the cached response file" do
- expect(@provider.preseed_resource('java', '6').backup).to be_false
+ expect(@provider.preseed_resource('java', '6').backup).to be_falsey
end
it "sets the install path of the resource to $file_cache/$cookbook/$pkg_name-$pkg_version.seed" do
@@ -425,3 +425,277 @@ describe Chef::Provider::Package do
end
end
+
+describe "Chef::Provider::Package - Multi" do
+ before do
+ @node = Chef::Node.new
+ @events = Chef::EventDispatch::Dispatcher.new
+ @run_context = Chef::RunContext.new(@node, {}, @events)
+ @new_resource = Chef::Resource::Package.new(['emacs', 'vi'])
+ @current_resource = Chef::Resource::Package.new(['emacs', 'vi'])
+ @provider = Chef::Provider::Package.new(@new_resource, @run_context)
+ @provider.current_resource = @current_resource
+ @provider.candidate_version = ['1.0', '6.2']
+ end
+
+ describe "when installing multiple packages" do
+ before(:each) do
+ @provider.current_resource = @current_resource
+ allow(@provider).to receive(:install_package).and_return(true)
+ end
+
+ it "installs the candidate versions when none are installed" do
+ expect(@provider).to receive(:install_package).with(
+ ["emacs", "vi"],
+ ["1.0", "6.2"]
+ ).and_return(true)
+ @provider.run_action(:install)
+ expect(@new_resource).to be_updated
+ end
+
+ it "installs the candidate versions when some are installed" do
+ expect(@provider).to receive(:install_package).with(
+ [ 'vi' ],
+ [ '6.2' ]
+ ).and_return(true)
+ @current_resource.version(['1.0', nil])
+ @provider.run_action(:install)
+ expect(@new_resource).to be_updated
+ end
+
+ it "installs the specified version when some are out of date" do
+ @current_resource.version(['1.0', '6.2'])
+ @new_resource.version(['1.0', '6.1'])
+ @provider.run_action(:install)
+ expect(@new_resource).to be_updated
+ end
+
+ it "does not install any version if all are installed at the right version" do
+ @current_resource.version(['1.0', '6.2'])
+ @new_resource.version(['1.0', '6.2'])
+ @provider.run_action(:install)
+ expect(@new_resource).not_to be_updated_by_last_action
+ end
+
+ it "does not install any version if all are installed, and no version was specified" do
+ @current_resource.version(['1.0', '6.2'])
+ @provider.run_action(:install)
+ expect(@new_resource).not_to be_updated_by_last_action
+ end
+
+ it "raises an exception if both are not installed and no caondidates are available" do
+ @current_resource.version([nil, nil])
+ @provider.candidate_version = [nil, nil]
+ expect { @provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
+ end
+
+ it "raises an exception if one is not installed and no candidates are available" do
+ @current_resource.version(['1.0', nil])
+ @provider.candidate_version = ['1.0', nil]
+ expect { @provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
+ end
+
+ it "does not raise an exception if the packages are installed or have a candidate" do
+ @current_resource.version(['1.0', nil])
+ @provider.candidate_version = [nil, '6.2']
+ expect { @provider.run_action(:install) }.not_to raise_error
+ end
+
+ it "raises an exception if an explicit version is asked for, an old version is installed, but no candidate" do
+ @new_resource.version ['1.0', '6.2']
+ @current_resource.version(['1.0', '6.1'])
+ @provider.candidate_version = ['1.0', nil]
+ expect { @provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
+ end
+
+ it "does not raise an exception if an explicit version is asked for, and is installed, but no candidate" do
+ @new_resource.version ['1.0', '6.2']
+ @current_resource.version(['1.0', '6.2'])
+ @provider.candidate_version = ['1.0', nil]
+ expect { @provider.run_action(:install) }.not_to raise_error
+ end
+
+ it "raise an exception if an explicit version is asked for, and is not installed, and no candidate" do
+ @new_resource.version ['1.0', '6.2']
+ @current_resource.version(['1.0', nil])
+ @provider.candidate_version = ['1.0', nil]
+ expect { @provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
+ end
+
+ it "does not raise an exception if an explicit version is asked for, and is not installed, and there is a candidate" do
+ @new_resource.version ['1.0', '6.2']
+ @current_resource.version(['1.0', nil])
+ @provider.candidate_version = ['1.0', '6.2']
+ expect { @provider.run_action(:install) }.not_to raise_error
+ end
+ end
+
+ describe "when upgrading multiple packages" do
+ before(:each) do
+ @provider.current_resource = @current_resource
+ allow(@provider).to receive(:upgrade_package).and_return(true)
+ end
+
+ it "should upgrade the package if the current versions are not the candidate version" do
+ @current_resource.version ['0.9', '6.1']
+ expect(@provider).to receive(:upgrade_package).with(
+ @new_resource.package_name,
+ @provider.candidate_version
+ ).and_return(true)
+ @provider.run_action(:upgrade)
+ expect(@new_resource).to be_updated_by_last_action
+ end
+
+ it "should upgrade the package if some of current versions are not the candidate versions" do
+ @current_resource.version ['1.0', '6.1']
+ expect(@provider).to receive(:upgrade_package).with(
+ ["vi"],
+ ["6.2"]
+ ).and_return(true)
+ @provider.run_action(:upgrade)
+ expect(@new_resource).to be_updated_by_last_action
+ end
+
+ it "should not install the package if the current versions are the candidate version" do
+ @current_resource.version ['1.0', '6.2']
+ expect(@provider).not_to receive(:upgrade_package)
+ @provider.run_action(:upgrade)
+ expect(@new_resource).not_to be_updated_by_last_action
+ end
+
+ it "should raise an exception if both are not installed and no caondidates are available" do
+ @current_resource.version([nil, nil])
+ @provider.candidate_version = [nil, nil]
+ expect { @provider.run_action(:upgrade) }.to raise_error(Chef::Exceptions::Package)
+ end
+
+ it "should raise an exception if one is not installed and no candidates are available" do
+ @current_resource.version(['1.0', nil])
+ @provider.candidate_version = ['1.0', nil]
+ expect { @provider.run_action(:upgrade) }.to raise_error(Chef::Exceptions::Package)
+ end
+
+ it "should not raise an exception if the packages are installed or have a candidate" do
+ @current_resource.version(['1.0', nil])
+ @provider.candidate_version = [nil, '6.2']
+ expect { @provider.run_action(:upgrade) }.not_to raise_error
+ end
+
+ it "should not raise an exception if the packages are installed or have a candidate" do
+ @current_resource.version(['1.0', nil])
+ @provider.candidate_version = [nil, '6.2']
+ expect { @provider.run_action(:upgrade) }.not_to raise_error
+ end
+ end
+
+ describe "When removing multiple packages " do
+ before(:each) do
+ allow(@provider).to receive(:remove_package).and_return(true)
+ @current_resource.version ['1.0', '6.2']
+ end
+
+ it "should remove the packages if all are installed" do
+ expect(@provider).to be_removing_package
+ expect(@provider).to receive(:remove_package).with(['emacs', 'vi'], nil)
+ @provider.run_action(:remove)
+ expect(@new_resource).to be_updated
+ expect(@new_resource).to be_updated_by_last_action
+ end
+
+ it "should remove the packages if some are installed" do
+ @current_resource.version ['1.0', nil]
+ expect(@provider).to be_removing_package
+ expect(@provider).to receive(:remove_package).with(['emacs', 'vi'], nil)
+ @provider.run_action(:remove)
+ expect(@new_resource).to be_updated
+ expect(@new_resource).to be_updated_by_last_action
+ end
+
+ it "should remove the packages at a specific version if they are installed at that version" do
+ @new_resource.version ['1.0', '6.2']
+ expect(@provider).to be_removing_package
+ expect(@provider).to receive(:remove_package).with(['emacs', 'vi'], ['1.0', '6.2'])
+ @provider.run_action(:remove)
+ expect(@new_resource).to be_updated_by_last_action
+ end
+
+ it "should remove the packages at a specific version any are is installed at that version" do
+ @new_resource.version ['0.5', '6.2']
+ expect(@provider).to be_removing_package
+ expect(@provider).to receive(:remove_package).with(['emacs', 'vi'], ['0.5', '6.2'])
+ @provider.run_action(:remove)
+ expect(@new_resource).to be_updated_by_last_action
+ end
+
+ it "should not remove the packages at a specific version if they are not installed at that version" do
+ @new_resource.version ['0.5', '6.0']
+ expect(@provider).not_to be_removing_package
+ expect(@provider).not_to receive(:remove_package)
+ @provider.run_action(:remove)
+ expect(@new_resource).not_to be_updated_by_last_action
+ end
+
+ it "should not remove the packages if they are not installed" do
+ expect(@provider).not_to receive(:remove_package)
+ allow(@current_resource).to receive(:version).and_return(nil)
+ @provider.run_action(:remove)
+ expect(@new_resource).not_to be_updated_by_last_action
+ end
+
+ end
+
+ describe "When purging multiple packages " do
+ before(:each) do
+ allow(@provider).to receive(:purge_package).and_return(true)
+ @current_resource.version ['1.0', '6.2']
+ end
+
+ it "should purge the packages if all are installed" do
+ expect(@provider).to be_removing_package
+ expect(@provider).to receive(:purge_package).with(['emacs', 'vi'], nil)
+ @provider.run_action(:purge)
+ expect(@new_resource).to be_updated
+ expect(@new_resource).to be_updated_by_last_action
+ end
+
+ it "should purge the packages if some are installed" do
+ @current_resource.version ['1.0', nil]
+ expect(@provider).to be_removing_package
+ expect(@provider).to receive(:purge_package).with(['emacs', 'vi'], nil)
+ @provider.run_action(:purge)
+ expect(@new_resource).to be_updated
+ expect(@new_resource).to be_updated_by_last_action
+ end
+
+ it "should purge the packages at a specific version if they are installed at that version" do
+ @new_resource.version ['1.0', '6.2']
+ expect(@provider).to be_removing_package
+ expect(@provider).to receive(:purge_package).with(['emacs', 'vi'], ['1.0', '6.2'])
+ @provider.run_action(:purge)
+ expect(@new_resource).to be_updated_by_last_action
+ end
+
+ it "should purge the packages at a specific version any are is installed at that version" do
+ @new_resource.version ['0.5', '6.2']
+ expect(@provider).to be_removing_package
+ expect(@provider).to receive(:purge_package).with(['emacs', 'vi'], ['0.5', '6.2'])
+ @provider.run_action(:purge)
+ expect(@new_resource).to be_updated_by_last_action
+ end
+
+ it "should not purge the packages at a specific version if they are not installed at that version" do
+ @new_resource.version ['0.5', '6.0']
+ expect(@provider).not_to be_removing_package
+ expect(@provider).not_to receive(:purge_package)
+ @provider.run_action(:purge)
+ expect(@new_resource).not_to be_updated_by_last_action
+ end
+
+ it "should not purge the packages if they are not installed" do
+ expect(@provider).not_to receive(:purge_package)
+ allow(@current_resource).to receive(:version).and_return(nil)
+ @provider.run_action(:purge)
+ expect(@new_resource).not_to be_updated_by_last_action
+ end
+ end
+end