summaryrefslogtreecommitdiff
path: root/spec/unit/provider/package
diff options
context:
space:
mode:
authorChris Doherty <cdoherty@getchef.com>2016-02-01 11:48:16 -0800
committerChris Doherty <cdoherty@chef.io>2016-02-03 22:11:04 -0800
commitb96cdfef5cc439fcd48e48fc6784fe1694a4796d (patch)
tree25cb59a9ff4919fdc425e36da04549c87d837d44 /spec/unit/provider/package
parenta6864e6681e2bed416376fee865f19db7ce150f9 (diff)
downloadchef-b96cdfef5cc439fcd48e48fc6784fe1694a4796d.tar.gz
Chocolatey provider: Raise a MissingLibrary exception if we can't find Chocolatey.cd/choco-error-msg
Diffstat (limited to 'spec/unit/provider/package')
-rw-r--r--spec/unit/provider/package/chocolatey_spec.rb43
1 files changed, 42 insertions, 1 deletions
diff --git a/spec/unit/provider/package/chocolatey_spec.rb b/spec/unit/provider/package/chocolatey_spec.rb
index bf17bfe808..d550e55445 100644
--- a/spec/unit/provider/package/chocolatey_spec.rb
+++ b/spec/unit/provider/package/chocolatey_spec.rb
@@ -30,7 +30,8 @@ describe Chef::Provider::Package::Chocolatey do
Chef::Provider::Package::Chocolatey.new(new_resource, run_context)
end
- let(:choco_exe) { 'C:\ProgramData\chocolatey\bin\choco.exe' }
+ let(:choco_install_path) { "C:\\ProgramData\\chocolatey" }
+ let(:choco_exe) { "#{choco_install_path}\\bin\\choco.exe" }
# installed packages (ConEmu is upgradable)
let(:local_list_stdout) do
@@ -41,6 +42,7 @@ ConEmu|15.10.25.0
end
before do
+ 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)
@@ -460,4 +462,43 @@ munin-node|1.6.1.20130823
expect(new_resource).to be_updated_by_last_action
end
end
+
+ describe "#choco_exe" do
+ it "calls #choco_install_path" do
+ # un-stub #choco_exe from the before{} block.
+ allow(provider).to receive(:choco_exe).and_call_original
+ expect(provider).to receive(:choco_install_path).and_return("spork")
+ provider.instance_variable_set("@choco_exe", nil)
+
+ expect(provider.send(:choco_exe)).to match(%r{spork[/\\]bin[/\\]choco.exe})
+ end
+ end
+end
+
+describe "behavior when Chocolatey is not installed" do
+ let(:new_resource) { Chef::Resource::ChocolateyPackage.new("git") }
+
+ let(:provider) do
+ node = Chef::Node.new
+ events = Chef::EventDispatch::Dispatcher.new
+ run_context = Chef::RunContext.new(node, {}, events)
+ Chef::Provider::Package::Chocolatey.new(new_resource, run_context)
+ end
+
+ before {
+ allow(provider).to receive(:choco_install_path).and_return("")
+ provider.instance_variable_set("@choco_install_path", nil)
+
+ # we don't care what this returns, but we have to let it be called.
+ allow(provider).to receive(:shell_out!).and_return(double(:stdout => ""))
+ }
+
+ context "#define_resource_requirements" do
+ it "triggers a MissingLibrary exception when Chocolatey is not installed" do
+ provider.action = :install
+ provider.load_current_resource
+ provider.define_resource_requirements
+ expect { provider.process_resource_requirements }.to raise_error(Chef::Exceptions::MissingLibrary, /Could not locate.*install.*cookbook.*PowerShell.*GetEnvironmentVariable/m)
+ end
+ end
end