diff options
author | Chris Doherty <cdoherty@getchef.com> | 2014-09-04 15:27:32 -0700 |
---|---|---|
committer | Chris Doherty <cdoherty@getchef.com> | 2014-09-10 16:34:25 -0700 |
commit | 72d81b6e571f7057e7df24d6f0caaf5c70802f04 (patch) | |
tree | 4dcfd82eaae387ccb36e6308e5ce6eb5508c8ebd | |
parent | 6613b43f259ee26460ac99b6f04a5fc0a4896dbd (diff) | |
download | chef-72d81b6e571f7057e7df24d6f0caaf5c70802f04.tar.gz |
Spec for the actual reboot code.
-rw-r--r-- | lib/chef/rebooter.rb | 18 | ||||
-rw-r--r-- | spec/functional/rebooter_spec.rb | 64 |
2 files changed, 77 insertions, 5 deletions
diff --git a/lib/chef/rebooter.rb b/lib/chef/rebooter.rb index acaf0ed854..f898a6430e 100644 --- a/lib/chef/rebooter.rb +++ b/lib/chef/rebooter.rb @@ -36,12 +36,12 @@ class Chef "shutdown -r #{shutdown_time}" end Chef::Log.warn "Shutdown command (not running): '#{cmd}'" - # for ease of testing we are not yet actually rebooting. - #shell_out!(cmd) + + Sheller.shell_out!(cmd) end - def reboot_if_needed!(node) - @node = node + def reboot_if_needed!(this_node) + @node = this_node @reboot_info = node.run_context.reboot_info if node.run_context.reboot_requested? @@ -49,5 +49,13 @@ class Chef end end end # end class instance stuff. + + # this lets us stub #shell_out! in specs, while still calling the actual other functions. + class Sheller + # for ease of testing, we are not yet actually rebooting. + def self.shell_out!(cmd) + #shell_out!(cmd) + end + end end -end
\ No newline at end of file +end diff --git a/spec/functional/rebooter_spec.rb b/spec/functional/rebooter_spec.rb new file mode 100644 index 0000000000..3e87d4ee16 --- /dev/null +++ b/spec/functional/rebooter_spec.rb @@ -0,0 +1,64 @@ +# +# Author:: Chris Doherty <cdoherty@getchef.com>) +# Copyright:: Copyright (c) 2014 Chef, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Rebooter do + + let(:reboot_info) do + { + :delay_mins => 5, + :requested_by => "reboot resource functional test", + :reason => "reboot resource spec test" + } + end + + def create_resource + resource = Chef::Resource::Reboot.new(expected[:requested_by], run_context) + resource.delay_mins(expected[:delay_mins]) + resource.reason(expected[:reason]) + resource + end + + let(:run_context) do + node = Chef::Node.new + events = Chef::EventDispatch::Dispatcher.new + Chef::RunContext.new(node, {}, events) + end + + let(:rebooter) { Chef::Rebooter } + + let(:sheller) { Chef::Rebooter::Sheller } + + describe '#reboot_if_needed!' do + + it 'should call #shell_out! when reboot has been requested' do + run_context.request_reboot(reboot_info) + + expect(sheller).to receive(:shell_out!).once + rebooter.reboot_if_needed!(run_context.node) + + run_context.cancel_reboot + end + + it 'should not call #shell_out! when reboot has not been requested' do + expect(sheller).to receive(:shell_out!).exactly(0).times + rebooter.reboot_if_needed!(run_context.node) + end + end +end |