From 7f32905c7b5600de2004f83bf4f05053db2b3b12 Mon Sep 17 00:00:00 2001 From: Matt Wrock Date: Tue, 12 Jan 2016 09:06:07 -0800 Subject: assert candidates exist for alternate sources and when pinning versions --- spec/unit/provider/package/chocolatey_spec.rb | 34 ++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'spec/unit/provider') diff --git a/spec/unit/provider/package/chocolatey_spec.rb b/spec/unit/provider/package/chocolatey_spec.rb index d2d6fabb19..b2e1d2daaf 100644 --- a/spec/unit/provider/package/chocolatey_spec.rb +++ b/spec/unit/provider/package/chocolatey_spec.rb @@ -54,7 +54,7 @@ git|2.6.2 munin-node|1.6.1.20130823 EOF remote_list_obj = double(stdout: remote_list_stdout) - allow(provider).to receive(:shell_out!).with("#{choco_exe} list -r #{package_names.join ' '}#{args}", {timeout: timeout}).and_return(remote_list_obj) + allow(provider).to receive(:shell_out!).with("#{choco_exe} list -ar #{package_names.join ' '}#{args}", {timeout: timeout}).and_return(remote_list_obj) end describe "#initialize" do @@ -284,12 +284,30 @@ munin-node|1.6.1.20130823 expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package) end + it "installing a package version that does not exist throws an error" do + allow_remote_list(["git"]) + new_resource.package_name("git") + new_resource.version("2.7.0") + provider.load_current_resource + expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package) + end + it "installing multiple packages with a package that does not exist throws an error" do allow_remote_list(["git", "package-does-not-exist"]) new_resource.package_name(["git", "package-does-not-exist"]) provider.load_current_resource expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package) end + + context "alternate source" do + it "installing a package that does not exist throws an error" do + allow_remote_list(["package-does-not-exist"], " -source alternate_source") + new_resource.package_name("package-does-not-exist") + new_resource.source("alternate_source") + provider.load_current_resource + expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package) + end + end end describe "#action_upgrade" do @@ -330,9 +348,9 @@ munin-node|1.6.1.20130823 it "version pins work as well" do allow_remote_list(["git"]) - new_resource.version("99.99.99.99") + new_resource.version("2.6.2") provider.load_current_resource - expect(provider).to receive(:shell_out!).with("#{choco_exe} upgrade -y -version 99.99.99.99 git", {:timeout=>timeout}) + expect(provider).to receive(:shell_out!).with("#{choco_exe} upgrade -y -version 2.6.2 git", {:timeout=>timeout}) provider.run_action(:upgrade) expect(new_resource).to be_updated_by_last_action end @@ -358,6 +376,16 @@ munin-node|1.6.1.20130823 provider.load_current_resource expect { provider.run_action(:upgrade) }.to raise_error(Chef::Exceptions::Package) end + + context "alternate source" do + it "installing a package that does not exist throws an error" do + allow_remote_list(["package-does-not-exist"], " -source alternate_source") + new_resource.package_name("package-does-not-exist") + new_resource.source("alternate_source") + provider.load_current_resource + expect { provider.run_action(:upgrade) }.to raise_error(Chef::Exceptions::Package) + end + end end describe "#action_remove" do -- cgit v1.2.1