summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/provider/package/chocolatey.rb20
-rw-r--r--spec/unit/provider/package/chocolatey_spec.rb34
2 files changed, 49 insertions, 5 deletions
diff --git a/lib/chef/provider/package/chocolatey.rb b/lib/chef/provider/package/chocolatey.rb
index 3f52370939..4f0e680646 100644
--- a/lib/chef/provider/package/chocolatey.rb
+++ b/lib/chef/provider/package/chocolatey.rb
@@ -40,6 +40,19 @@ class Chef
current_resource
end
+ def define_resource_requirements
+ super
+
+ # Chocolatey source attribute points to an alternate feed
+ # and not a package specific alternate source like other providers
+ # so we want to assert candidates exist for the alternate source
+ requirements.assert(:upgrade, :install) do |a|
+ a.assertion { candidates_exist_for_all_uninstalled? }
+ a.failure_message(Chef::Exceptions::Package, "No candidate version available for #{packages_missing_candidates.join(", ")}")
+ a.whyrun("Assuming a repository that offers #{packages_missing_candidates.join(", ")} would have been configured")
+ end
+ end
+
# Lazy initializer for candidate_version. A nil value means that there is no candidate
# version and the package is not installable (generally an error).
#
@@ -197,7 +210,7 @@ class Chef
def available_packages
@available_packages ||=
begin
- cmd = [ "list -r #{package_name_array.join ' '}" ]
+ cmd = [ "list -ar #{package_name_array.join ' '}" ]
cmd.push( "-source #{new_resource.source}" ) if new_resource.source
parse_list_output(*cmd)
end
@@ -220,7 +233,10 @@ class Chef
hash = {}
choco_command(*args).stdout.each_line do |line|
name, version = line.split('|')
- hash[name.downcase] = version.chomp
+ version = version.chomp
+ if desired_name_versions[name].nil? || desired_name_versions[name] == version
+ hash[name.downcase] = version
+ end
end
hash
end
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