summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Wrock <matt@mattwrock.com>2016-02-11 18:57:44 -0800
committerMatt Wrock <matt@mattwrock.com>2016-02-11 18:57:44 -0800
commit0ef585544e196e451dbc30573ff5403905328f90 (patch)
tree3f20f6a8081a8a753544e76b95e851aa22ad16c6
parentc700c2d999a5767931cf43e6f8191ed5961d2137 (diff)
downloadchef-0ef585544e196e451dbc30573ff5403905328f90.tar.gz
do not include source parameter when removing a chocolatey package and ensure source is used on all functional testsno_web
-rw-r--r--lib/chef/provider/package/chocolatey.rb7
-rw-r--r--spec/functional/resource/chocolatey_package_spec.rb14
2 files changed, 14 insertions, 7 deletions
diff --git a/lib/chef/provider/package/chocolatey.rb b/lib/chef/provider/package/chocolatey.rb
index 14613b0218..e111beb9b5 100644
--- a/lib/chef/provider/package/chocolatey.rb
+++ b/lib/chef/provider/package/chocolatey.rb
@@ -126,7 +126,7 @@ EOS
# @param names [Array<String>] array of package names to install
# @param versions [Array<String>] array of versions to install
def remove_package(names, versions)
- choco_command("uninstall -y", cmd_args, *names)
+ choco_command("uninstall -y", cmd_args(include_source: false), *names)
end
# Support :uninstall as an action in order for users to easily convert
@@ -206,10 +206,11 @@ EOS
# Helper to construct optional args out of new_resource
#
+ # @param include_source [Boolean] should the source parameter be added
# @return [String] options from new_resource or empty string
- def cmd_args
+ def cmd_args(include_source: true)
cmd_args = [ new_resource.options ]
- cmd_args.push( "-source #{new_resource.source}" ) if new_resource.source
+ cmd_args.push( "-source #{new_resource.source}" ) if new_resource.source && include_source
args_to_string(*cmd_args)
end
diff --git a/spec/functional/resource/chocolatey_package_spec.rb b/spec/functional/resource/chocolatey_package_spec.rb
index e442008060..fb51fd2d64 100644
--- a/spec/functional/resource/chocolatey_package_spec.rb
+++ b/spec/functional/resource/chocolatey_package_spec.rb
@@ -35,12 +35,12 @@ describe Chef::Resource::ChocolateyPackage, :windows_only do
subject do
new_resource = Chef::Resource::ChocolateyPackage.new("test choco package", run_context)
new_resource.package_name package_name
- new_resource.source package_source if package_source
+ new_resource.source package_source
new_resource
end
context "installing a package" do
- after { Chef::Resource::ChocolateyPackage.new(package_name, run_context).run_action(:remove) }
+ after { remove_package }
it "installs the latest version" do
subject.run_action(:install)
@@ -90,7 +90,7 @@ describe Chef::Resource::ChocolateyPackage, :windows_only do
end
context "upgrading a package" do
- after { Chef::Resource::ChocolateyPackage.new(package_name, run_context).run_action(:remove) }
+ after { remove_package }
it "upgrades to a specific version" do
subject.version "1.0"
@@ -117,8 +117,14 @@ describe Chef::Resource::ChocolateyPackage, :windows_only do
context "removing a package" do
it "removes an installed package" do
subject.run_action(:install)
- Chef::Resource::ChocolateyPackage.new(package_name, run_context).run_action(:remove)
+ remove_package
expect(package_list.call).to eq("")
end
end
+
+ def remove_package
+ pkg_to_remove = Chef::Resource::ChocolateyPackage.new(package_name, run_context)
+ pkg_to_remove.source = package_source
+ pkg_to_remove.run_action(:remove)
+ end
end