summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2017-01-05 09:19:40 -0500
committerGitHub <noreply@github.com>2017-01-05 09:19:40 -0500
commitd5d0ec41352c596532f58ce643e88f0606883064 (patch)
tree8e69c9475a9ae174cc0d8426bbe91929ea8db2b7
parentcd1171f9114e70a4fb2e23b1b3c02da3853f1a46 (diff)
parent586f1f9b94c0c3900e7f01961d9dd18ddbabebfc (diff)
downloadchef-d5d0ec41352c596532f58ce643e88f0606883064.tar.gz
Merge pull request #5688 from MsysTechnologiesllc/vj/adding_returns_porpert_to_chocolatey_package
Adding returns property to chocolatey_package resource
-rw-r--r--lib/chef/provider/package/chocolatey.rb4
-rw-r--r--lib/chef/resource/chocolatey_package.rb1
-rw-r--r--spec/unit/provider/package/chocolatey_spec.rb42
-rw-r--r--spec/unit/resource/chocolatey_package_spec.rb12
4 files changed, 37 insertions, 22 deletions
diff --git a/lib/chef/provider/package/chocolatey.rb b/lib/chef/provider/package/chocolatey.rb
index 90624b9a0b..02a196fa8c 100644
--- a/lib/chef/provider/package/chocolatey.rb
+++ b/lib/chef/provider/package/chocolatey.rb
@@ -169,7 +169,7 @@ EOS
# @param args [String] variable number of string arguments
# @return [Mixlib::ShellOut] object returned from shell_out!
def choco_command(*args)
- shell_out_with_timeout!(args_to_string(choco_exe, *args))
+ shell_out_with_timeout!(args_to_string(choco_exe, *args), { :returns => new_resource.returns })
end
# Use the available_packages Hash helper to create an array suitable for
@@ -236,6 +236,7 @@ EOS
available[name] = desired_name_versions[name] || raw[name]
end
end
+ @available_packages
end
# Installed packages in chocolatey as a Hash of names mapped to versions
@@ -244,6 +245,7 @@ EOS
# @return [Hash] name-to-version mapping of installed packages
def installed_packages
@installed_packages ||= Hash[*parse_list_output("list -l -r").flatten]
+ @installed_packages
end
# Helper to convert choco.exe list output to a Hash
diff --git a/lib/chef/resource/chocolatey_package.rb b/lib/chef/resource/chocolatey_package.rb
index 805d3a3121..5460661f6d 100644
--- a/lib/chef/resource/chocolatey_package.rb
+++ b/lib/chef/resource/chocolatey_package.rb
@@ -34,6 +34,7 @@ class Chef
property :package_name, [String, Array], coerce: proc { |x| [x].flatten }
property :version, [String, Array], coerce: proc { |x| [x].flatten }
+ property :returns, [Integer, Array], default: [ 0 ], desired_state: false
end
end
end
diff --git a/spec/unit/provider/package/chocolatey_spec.rb b/spec/unit/provider/package/chocolatey_spec.rb
index 0429a4b202..68b121960c 100644
--- a/spec/unit/provider/package/chocolatey_spec.rb
+++ b/spec/unit/provider/package/chocolatey_spec.rb
@@ -46,7 +46,7 @@ ConEmu|15.10.25.0
allow(provider).to receive(:choco_install_path).and_return(choco_install_path)
allow(provider).to receive(:choco_exe).and_return(choco_exe)
local_list_obj = double(:stdout => local_list_stdout)
- allow(provider).to receive(:shell_out!).with("#{choco_exe} list -l -r", { :timeout => timeout }).and_return(local_list_obj)
+ allow(provider).to receive(:shell_out!).with("#{choco_exe} list -l -r", { :returns => [0], :timeout => timeout }).and_return(local_list_obj)
end
def allow_remote_list(package_names, args = nil)
@@ -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 -r #{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}", { :returns => [0], timeout: timeout }).and_return(remote_list_obj)
end
describe "#initialize" do
@@ -180,7 +180,7 @@ munin-node|1.6.1.20130823
it "should install a single package" do
allow_remote_list(["git"])
provider.load_current_resource
- expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y git", { :timeout => timeout }).and_return(double)
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y git", { :returns => [0], :timeout => timeout }).and_return(double)
provider.run_action(:install)
expect(new_resource).to be_updated_by_last_action
end
@@ -191,7 +191,7 @@ munin-node|1.6.1.20130823
allow_remote_list(["git"])
new_resource.timeout(timeout)
provider.load_current_resource
- expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y git", { :timeout => timeout }).and_return(double)
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y git", { :returns => [0], :timeout => timeout }).and_return(double)
provider.run_action(:install)
expect(new_resource).to be_updated_by_last_action
end
@@ -220,7 +220,7 @@ munin-node|1.6.1.20130823
new_resource.package_name("ConEmu")
new_resource.version("15.10.25.1")
provider.load_current_resource
- expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y --version 15.10.25.1 conemu", { :timeout => timeout }).and_return(double)
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y --version 15.10.25.1 conemu", { :returns => [0], :timeout => timeout }).and_return(double)
provider.run_action(:install)
expect(new_resource).to be_updated_by_last_action
end
@@ -233,7 +233,7 @@ munin-node|1.6.1.20130823
new_resource.package_name(%w{chocolatey ConEmu})
new_resource.version([nil, "15.10.25.1"])
provider.load_current_resource
- expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y --version 15.10.25.1 conemu", { :timeout => timeout }).and_return(double)
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y --version 15.10.25.1 conemu", { :returns => [0], :timeout => timeout }).and_return(double)
provider.run_action(:install)
expect(new_resource).to be_updated_by_last_action
end
@@ -243,7 +243,7 @@ munin-node|1.6.1.20130823
new_resource.package_name("conemu")
new_resource.version("15.10.25.1")
provider.load_current_resource
- expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y --version 15.10.25.1 conemu", { :timeout => timeout }).and_return(double)
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y --version 15.10.25.1 conemu", { :returns => [0], :timeout => timeout }).and_return(double)
provider.run_action(:install)
expect(new_resource).to be_updated_by_last_action
end
@@ -253,8 +253,8 @@ munin-node|1.6.1.20130823
new_resource.package_name(%w{ConEmu git})
new_resource.version(["15.10.25.1", nil])
provider.load_current_resource
- expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y --version 15.10.25.1 conemu", { :timeout => timeout }).and_return(double)
- expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y git", { :timeout => timeout }).and_return(double)
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y --version 15.10.25.1 conemu", { :returns => [0], :timeout => timeout }).and_return(double)
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y git", { :returns => [0], :timeout => timeout }).and_return(double)
provider.run_action(:install)
expect(new_resource).to be_updated_by_last_action
end
@@ -263,7 +263,7 @@ munin-node|1.6.1.20130823
allow_remote_list(["git", "munin-node"])
new_resource.package_name(["git", "munin-node"])
provider.load_current_resource
- expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y git munin-node", { :timeout => timeout }).and_return(double)
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y git munin-node", { :returns => [0], :timeout => timeout }).and_return(double)
provider.run_action(:install)
expect(new_resource).to be_updated_by_last_action
end
@@ -273,7 +273,7 @@ munin-node|1.6.1.20130823
allow_remote_list(["git"], " -source localpackages")
new_resource.source("localpackages")
provider.load_current_resource
- expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y -source localpackages git", { :timeout => timeout }).and_return(double)
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y -source localpackages git", { :returns => [0], :timeout => timeout }).and_return(double)
provider.run_action(:install)
expect(new_resource).to be_updated_by_last_action
end
@@ -283,7 +283,7 @@ munin-node|1.6.1.20130823
allow_remote_list(["git"])
new_resource.options("-force")
provider.load_current_resource
- expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y -force git", { :timeout => timeout }).and_return(double)
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y -force git", { :returns => [0], :timeout => timeout }).and_return(double)
provider.run_action(:install)
expect(new_resource).to be_updated_by_last_action
end
@@ -317,7 +317,7 @@ munin-node|1.6.1.20130823
it "should install a package that is not installed" do
allow_remote_list(["git"])
provider.load_current_resource
- expect(provider).to receive(:shell_out!).with("#{choco_exe} upgrade -y git", { :timeout => timeout }).and_return(double)
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} upgrade -y git", { :returns => [0], :timeout => timeout }).and_return(double)
provider.run_action(:upgrade)
expect(new_resource).to be_updated_by_last_action
end
@@ -326,7 +326,7 @@ munin-node|1.6.1.20130823
allow_remote_list(["ConEmu"])
new_resource.package_name("ConEmu")
provider.load_current_resource
- expect(provider).to receive(:shell_out!).with("#{choco_exe} upgrade -y conemu", { :timeout => timeout }).and_return(double)
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} upgrade -y conemu", { :returns => [0], :timeout => timeout }).and_return(double)
provider.run_action(:upgrade)
expect(new_resource).to be_updated_by_last_action
end
@@ -335,7 +335,7 @@ munin-node|1.6.1.20130823
allow_remote_list(["conemu"])
new_resource.package_name("conemu")
provider.load_current_resource
- expect(provider).to receive(:shell_out!).with("#{choco_exe} upgrade -y conemu", { :timeout => timeout }).and_return(double)
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} upgrade -y conemu", { :returns => [0], :timeout => timeout }).and_return(double)
provider.run_action(:upgrade)
expect(new_resource).to be_updated_by_last_action
end
@@ -344,7 +344,7 @@ munin-node|1.6.1.20130823
allow_remote_list(["chocolatey"])
new_resource.package_name("chocolatey")
provider.load_current_resource
- expect(provider).not_to receive(:shell_out!).with("#{choco_exe} upgrade -y chocolatey", { :timeout => timeout })
+ expect(provider).not_to receive(:shell_out!).with("#{choco_exe} upgrade -y chocolatey", { :returns => [0], :timeout => timeout })
provider.run_action(:upgrade)
expect(new_resource).not_to be_updated_by_last_action
end
@@ -353,7 +353,7 @@ munin-node|1.6.1.20130823
allow_remote_list(["git"])
new_resource.version("2.6.2")
provider.load_current_resource
- expect(provider).to receive(:shell_out!).with("#{choco_exe} upgrade -y --version 2.6.2 git", { :timeout => timeout })
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} upgrade -y --version 2.6.2 git", { :returns => [0], :timeout => timeout })
provider.run_action(:upgrade)
expect(new_resource).to be_updated_by_last_action
end
@@ -361,7 +361,7 @@ munin-node|1.6.1.20130823
it "upgrading multiple packages uses a single command" do
allow_remote_list(%w{conemu git})
new_resource.package_name(%w{conemu git})
- expect(provider).to receive(:shell_out!).with("#{choco_exe} upgrade -y conemu git", { :timeout => timeout }).and_return(double)
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} upgrade -y conemu git", { :returns => [0], :timeout => timeout }).and_return(double)
provider.run_action(:upgrade)
expect(new_resource).to be_updated_by_last_action
end
@@ -413,7 +413,7 @@ munin-node|1.6.1.20130823
allow_remote_list(["ConEmu"])
new_resource.package_name("ConEmu")
provider.load_current_resource
- expect(provider).to receive(:shell_out!).with("#{choco_exe} uninstall -y ConEmu", { :timeout => timeout }).and_return(double)
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} uninstall -y ConEmu", { :returns => [0], :timeout => timeout }).and_return(double)
provider.run_action(:remove)
expect(new_resource).to be_updated_by_last_action
end
@@ -422,7 +422,7 @@ munin-node|1.6.1.20130823
allow_remote_list(["conemu"])
new_resource.package_name("conemu")
provider.load_current_resource
- expect(provider).to receive(:shell_out!).with("#{choco_exe} uninstall -y conemu", { :timeout => timeout }).and_return(double)
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} uninstall -y conemu", { :returns => [0], :timeout => timeout }).and_return(double)
provider.run_action(:remove)
expect(new_resource).to be_updated_by_last_action
end
@@ -432,7 +432,7 @@ munin-node|1.6.1.20130823
allow_remote_list(%w{git conemu})
new_resource.package_name(%w{git conemu})
provider.load_current_resource
- expect(provider).to receive(:shell_out!).with("#{choco_exe} uninstall -y conemu", { :timeout => timeout }).and_return(double)
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} uninstall -y conemu", { :returns => [0], :timeout => timeout }).and_return(double)
provider.run_action(:remove)
expect(new_resource).to be_updated_by_last_action
end
diff --git a/spec/unit/resource/chocolatey_package_spec.rb b/spec/unit/resource/chocolatey_package_spec.rb
index e43803a65f..9b433045c1 100644
--- a/spec/unit/resource/chocolatey_package_spec.rb
+++ b/spec/unit/resource/chocolatey_package_spec.rb
@@ -64,4 +64,16 @@ describe Chef::Resource::ChocolateyPackage do
resource.version(["1.2.3", "4.5.6"])
expect(resource.version).to eql(["1.2.3", "4.5.6"])
end
+
+ it "the default returns should be 0" do
+ expect(resource.returns).to eql([0])
+ end
+
+ # Integer, Array
+ [ 0, [0, 48, 49] ].each do |val|
+ it "supports setting an alternate return value as a #{val.class}" do
+ resource.returns(val)
+ expect(resource.returns).to eql(val)
+ end
+ end
end