summaryrefslogtreecommitdiff
path: root/spec/functional/resource/reboot_spec.rb
diff options
context:
space:
mode:
authorChris Doherty <cdoherty@getchef.com>2014-09-09 14:45:59 -0700
committerChris Doherty <cdoherty@getchef.com>2014-09-10 16:34:31 -0700
commitb35e001755d9eaa78092f937dfa94002ef9ec349 (patch)
tree9deb8a2fb2f2b72f7147fe8d9afd02f886b31b40 /spec/functional/resource/reboot_spec.rb
parent6d3aa8327224e25d6011b46b8873cab5e7a56031 (diff)
downloadchef-b35e001755d9eaa78092f937dfa94002ef9ec349.tar.gz
Re-implement immediate reboot using throw/catch, so all the end-of-run
tasks (e.g. report handlers) still get to run.
Diffstat (limited to 'spec/functional/resource/reboot_spec.rb')
-rw-r--r--spec/functional/resource/reboot_spec.rb39
1 files changed, 28 insertions, 11 deletions
diff --git a/spec/functional/resource/reboot_spec.rb b/spec/functional/resource/reboot_spec.rb
index 78feae6839..8e1ec80e8e 100644
--- a/spec/functional/resource/reboot_spec.rb
+++ b/spec/functional/resource/reboot_spec.rb
@@ -42,9 +42,22 @@ describe Chef::Resource::Reboot do
create_resource
end
- # the currently defined behavior for multiple calls to this resource is "last one wins."
+ shared_context 'testing run context modification' do
+ def test_reboot_action(resource)
+ reboot_info = resource.run_context.reboot_info
+ expect(reboot_info.keys.sort).to eq([:delay_mins, :reason, :requested_by, :timestamp])
+ expect(reboot_info[:delay_mins]).to eq(expected[:delay_mins])
+ expect(reboot_info[:reason]).to eq(expected[:reason])
+ expect(reboot_info[:requested_by]).to eq(expected[:requested_by])
+ expect(resource.run_context.reboot_requested?).to be_true
+ end
+ end
+
+ # the currently defined behavior for multiple calls to this resource is "last one wins."
describe 'the request_reboot_on_successful_run action' do
+ include_context 'testing run context modification'
+
before do
resource.run_action(:request_reboot_on_successful_run)
end
@@ -54,20 +67,24 @@ describe Chef::Resource::Reboot do
end
it 'should have modified the run context correctly' do
- reboot_info = resource.run_context.reboot_info
- expect(reboot_info.keys.sort).to eq([:delay_mins, :reason, :requested_by, :timestamp])
- expect(reboot_info[:delay_mins]).to eq(expected[:delay_mins])
- expect(reboot_info[:reason]).to eq(expected[:reason])
- expect(reboot_info[:requested_by]).to eq(expected[:requested_by])
-
- expect(resource.run_context.reboot_requested?).to be_true
+ test_reboot_action(resource)
end
end
describe 'the reboot_interrupt_run action' do
- it 'should have attempted to reboot the server' do
- expect(Chef::Platform::Rebooter).to receive(:reboot!).once
- resource.run_action(:reboot_interrupt_run)
+ include_context 'testing run context modification'
+
+ after do
+ resource.run_context.cancel_reboot
+ end
+
+ it 'should have modified the run context correctly' do
+ # this doesn't actually test the flow of Chef::Client#do_run, unfortunately.
+ expect {
+ resource.run_action(:reboot_interrupt_run)
+ }.to throw_symbol(:interrupt_run_and_reboot)
+
+ test_reboot_action(resource)
end
end