diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2014-10-22 13:26:20 -0700 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2014-10-24 15:07:13 -0700 |
commit | 82329160fa4753a135fa3ef84f2920d1dc24595f (patch) | |
tree | 26f0350da5cb05a455279f59ed772ff74076f57d | |
parent | 1c1fc315324a5929b1187dd7019f14ce8cf83f5c (diff) | |
download | chef-82329160fa4753a135fa3ef84f2920d1dc24595f.tar.gz |
Merge pull request #2264 from opscode/jdmundrawala/issue-2225jdmundrawala/11-issue-2225
Improve detection missing WhatIf support
-rw-r--r-- | lib/chef/util/dsc/local_configuration_manager.rb | 20 | ||||
-rw-r--r-- | spec/unit/util/dsc/local_configuration_manager_spec.rb | 7 |
2 files changed, 18 insertions, 9 deletions
diff --git a/lib/chef/util/dsc/local_configuration_manager.rb b/lib/chef/util/dsc/local_configuration_manager.rb index 4d49c8dcff..f498a2bfea 100644 --- a/lib/chef/util/dsc/local_configuration_manager.rb +++ b/lib/chef/util/dsc/local_configuration_manager.rb @@ -79,14 +79,18 @@ EOH end def log_what_if_exception(what_if_exception_output) - if what_if_exception_output.gsub(/\s+/, ' ') =~ /A parameter cannot be found that matches parameter name 'Whatif'/i - # LCM returns an error if any of the resources do not support the opptional What-If - Chef::Log::warn("Received error while testing configuration due to resource not supporting 'WhatIf'") - elsif dsc_module_import_failure?(what_if_exception_output) - Chef::Log::warn("Received error while testing configuration due to a module for an imported resource possibly not being fully installed:\n#{what_if_exception_output.gsub(/\s+/, ' ')}") - else - Chef::Log::warn("Received error while testing configuration:\n#{what_if_exception_output.gsub(/\s+/, ' ')}") - end + if whatif_not_supported?(what_if_exception_output) + # LCM returns an error if any of the resources do not support the opptional What-If + Chef::Log::warn("Received error while testing configuration due to resource not supporting 'WhatIf'") + elsif dsc_module_import_failure?(what_if_exception_output) + Chef::Log::warn("Received error while testing configuration due to a module for an imported resource possibly not being fully installed:\n#{what_if_exception_output.gsub(/\s+/, ' ')}") + else + Chef::Log::warn("Received error while testing configuration:\n#{what_if_exception_output.gsub(/\s+/, ' ')}") + end + end + + def whatif_not_supported?(what_if_exception_output) + !! (what_if_exception_output.gsub(/[\r\n]+/, '').gsub(/\s+/, ' ') =~ /A parameter cannot be found that matches parameter name 'Whatif'/i) end def dsc_module_import_failure?(what_if_output) diff --git a/spec/unit/util/dsc/local_configuration_manager_spec.rb b/spec/unit/util/dsc/local_configuration_manager_spec.rb index f630ac89d8..eb27e9e94e 100644 --- a/spec/unit/util/dsc/local_configuration_manager_spec.rb +++ b/spec/unit/util/dsc/local_configuration_manager_spec.rb @@ -32,7 +32,7 @@ EOH } let(:no_whatif_lcm_output) { <<-EOH -Start-DscConfiguration : A parameter cannot be found that matches parameter name 'whatif'. +Start-DscConfiguration : A parameter cannot be found\r\n that matches parameter name 'whatif'. At line:1 char:123 + run-somecommand -whatif + ~~~~~~~~ @@ -77,8 +77,13 @@ EOH let(:lcm_standard_error) { no_whatif_lcm_output } let(:lcm_cmdlet_success) { false } + it 'returns true when passed to #whatif_not_supported?' do + expect(lcm.send(:whatif_not_supported?, no_whatif_lcm_output)).to be_true + end + it 'should should return a (possibly empty) array of ResourceInfo instances' do expect(Chef::Log).to receive(:warn) + expect(lcm).to receive(:whatif_not_supported?).and_call_original test_configuration_result = nil expect {test_configuration_result = lcm.test_configuration('config')}.not_to raise_error expect(test_configuration_result.class).to be(Array) |