diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-03-15 14:28:36 -0700 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-03-20 14:38:49 -0700 |
commit | c71696269ea1865101b1857914f8afdd0a1e7e69 (patch) | |
tree | 9c952b95a7845f49a958dc17e523024a288dc486 | |
parent | e374b7ba24593c4ffaaf33bca27f623e9f758925 (diff) | |
download | chef-c71696269ea1865101b1857914f8afdd0a1e7e69.tar.gz |
Useful error message when dsc resource is not found
-rw-r--r-- | lib/chef/provider/dsc_resource.rb | 12 | ||||
-rw-r--r-- | lib/chef/util/dsc/resource_store.rb | 4 | ||||
-rw-r--r-- | spec/functional/resource/dsc_resource_spec.rb | 12 |
3 files changed, 22 insertions, 6 deletions
diff --git a/lib/chef/provider/dsc_resource.rb b/lib/chef/provider/dsc_resource.rb index c9b35fc089..fabb695803 100644 --- a/lib/chef/provider/dsc_resource.rb +++ b/lib/chef/provider/dsc_resource.rb @@ -44,7 +44,7 @@ class Chef def load_current_resource end - + def whyrun_supported? true end @@ -90,13 +90,19 @@ class Chef @converge_description end + def dsc_resource_name + new_resource.resource.to_s + end + def module_name @module_name ||= begin - found = resource_store.find(new_resource.resource.to_s) + found = resource_store.find(dsc_resource_name) r = case found.length when 0 - nil + raise Chef::Exceptions::ResourceNotFound, + "Could not find #{dsc_resource_name}. Check to make "\ + "sure that it shows up when running Get-DscResource" when 1 if found[0]['Module'].nil? :none diff --git a/lib/chef/util/dsc/resource_store.rb b/lib/chef/util/dsc/resource_store.rb index 643f5e8d2f..fdcecc2b3c 100644 --- a/lib/chef/util/dsc/resource_store.rb +++ b/lib/chef/util/dsc/resource_store.rb @@ -96,7 +96,9 @@ class DSC :object) result = cmdlet.run ret_val = result.return_value - if ret_val.is_a? Array + if ret_val.nil? + [] + elsif ret_val.is_a? Array ret_val else [ret_val] diff --git a/spec/functional/resource/dsc_resource_spec.rb b/spec/functional/resource/dsc_resource_spec.rb index 0279e5dbc6..a7c96e00d0 100644 --- a/spec/functional/resource/dsc_resource_spec.rb +++ b/spec/functional/resource/dsc_resource_spec.rb @@ -39,6 +39,14 @@ describe Chef::Resource::DscResource, :windows_powershell_dsc_only do } context 'when Powershell does not support Invoke-DscResource' - context 'when Powershell supports Invoke-DscResource' - + context 'when Powershell supports Invoke-DscResource' do + context 'with an invalid dsc resource' do + it 'raises an exception if the resource is not found' do + new_resource.resource 'thisdoesnotexist' + expect { new_resource.run_action(:run) }.to raise_error( + Chef::Exceptions::ResourceNotFound) + end + end + + end end |