summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Wrock <matt@mattwrock.com>2016-05-31 10:07:12 -0700
committerMatt Wrock <matt@mattwrock.com>2016-05-31 10:07:12 -0700
commitb067539105e77655e44395fa61f94547c50208f7 (patch)
treef8bb5237c362ec7600a3151e111d0509349ebeb3
parentf1ae18939d65fe9cabec7e31eb05ee3c3e9b6a2b (diff)
parent6fd05d1bb24d7eab5a38f4dbba9bf108a5f5bd2b (diff)
downloadchef-b067539105e77655e44395fa61f94547c50208f7.tar.gz
Merge pull request #4977 from chef/choco_ar
fixes #4968 and only retrieves the latest version of packages from chocolatey
-rw-r--r--lib/chef/provider/package/chocolatey.rb18
-rw-r--r--spec/functional/resource/chocolatey_package_spec.rb5
-rw-r--r--spec/unit/provider/package/chocolatey_spec.rb16
3 files changed, 9 insertions, 30 deletions
diff --git a/lib/chef/provider/package/chocolatey.rb b/lib/chef/provider/package/chocolatey.rb
index ebd3f987cd..36bc170590 100644
--- a/lib/chef/provider/package/chocolatey.rb
+++ b/lib/chef/provider/package/chocolatey.rb
@@ -229,13 +229,11 @@ EOS
def available_packages
@available_packages ||=
begin
- cmd = [ "list -ar #{package_name_array.join ' '}" ]
+ cmd = [ "list -r #{package_name_array.join ' '}" ]
cmd.push( "-source #{new_resource.source}" ) if new_resource.source
- parse_list_output(*cmd).each_with_object({}) do |name_version, available|
- name, version = name_version
- if desired_name_versions[name].nil? || desired_name_versions[name] == version
- available[name] = version
- end
+ raw = parse_list_output(*cmd)
+ raw.keys.each_with_object({}) do |name, available|
+ available[name] = desired_name_versions[name] || raw[name]
end
end
end
@@ -252,15 +250,15 @@ EOS
# (names are downcased for case-insenstive matching)
#
# @param cmd [String] command to run
- # @return [Array] list output converted to ruby Hash
+ # @return [Hash] list output converted to ruby Hash
def parse_list_output(*args)
- list = []
+ hash = {}
choco_command(*args).stdout.each_line do |line|
next if line.start_with?("Chocolatey v")
name, version = line.split("|")
- list << [ name.downcase, version.chomp ]
+ hash[name.downcase] = version.chomp
end
- list
+ hash
end
# Helper to downcase all names in an array
diff --git a/spec/functional/resource/chocolatey_package_spec.rb b/spec/functional/resource/chocolatey_package_spec.rb
index fb51fd2d64..7bb6698daf 100644
--- a/spec/functional/resource/chocolatey_package_spec.rb
+++ b/spec/functional/resource/chocolatey_package_spec.rb
@@ -82,11 +82,6 @@ describe Chef::Resource::ChocolateyPackage, :windows_only do
subject.package_name "blah"
expect { subject.run_action(:install) }.to raise_error Chef::Exceptions::Package
end
-
- it "raises if package version is not found" do
- subject.version "3.0"
- expect { subject.run_action(:install) }.to raise_error Chef::Exceptions::Package
- end
end
context "upgrading a package" do
diff --git a/spec/unit/provider/package/chocolatey_spec.rb b/spec/unit/provider/package/chocolatey_spec.rb
index 8eaa69b598..8344c3d0ec 100644
--- a/spec/unit/provider/package/chocolatey_spec.rb
+++ b/spec/unit/provider/package/chocolatey_spec.rb
@@ -59,7 +59,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 -ar #{package_names.join ' '}#{args}", { timeout: timeout }).and_return(remote_list_obj)
+ allow(provider).to receive(:shell_out!).with("#{choco_exe} list -r #{package_names.join ' '}#{args}", { timeout: timeout }).and_return(remote_list_obj)
end
describe "#initialize" do
@@ -84,12 +84,6 @@ munin-node|1.6.1.20130823
expect(provider.candidate_version).to eql(["2.6.1"])
end
- it "should set the candidate_version to nill if pinning to bogus version" do
- allow_remote_list(["git"])
- new_resource.version("2.5.0")
- expect(provider.candidate_version).to eql([nil])
- end
-
it "should set the candidate_version to nil if there is no candidate" do
allow_remote_list(["vim"])
new_resource.package_name("vim")
@@ -301,14 +295,6 @@ 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"])