-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathreboot_spec.rb
66 lines (53 loc) · 1.87 KB
/
reboot_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# encoding: UTF-8
require_relative 'spec_helper'
require File.join File.dirname(__FILE__), '..', 'files', 'default', 'reboot'
describe Chef::Handler::Reboot do
Mixlib::ShellOut.class_eval do
def run_command
true
end
end
let(:handler) { Chef::Handler::Reboot.new }
let(:node) do
ChefSpec::ServerRunner.new.converge('reboot-handler::default').node
end
let(:status) do
Chef::RunStatus.new node, Chef::EventDispatch::Dispatcher.new
end
it "doesn't reboot if the run failed" do
status.exception = Exception.new
expect(handler.run_report_unsafe(status)).not_to be
end
it "doesn't reboot if the node does not have the enabled_role" do
expect(handler.run_report_unsafe(status)).not_to be
end
it "doesn't reboot if the node has the enabled_role, but missing the reboot flag" do # rubocop:disable LineLength
allow(node).to receive(:roles).and_return ['booted']
expect(handler.run_report_unsafe(status)).not_to be
end
context 'with enabled_role and reboot flag' do
before do
allow(node).to receive(:roles).and_return ['booted']
node.run_state['reboot'] = true
end
it 'reboots' do
expect(handler.run_report_unsafe(status)).to be
end
it 'issues correct command' do
obj = double
allow(node).to receive(:run_command).and_return true
allow_any_instance_of(Mixlib::ShellOut).to receive(:new)
.with('sync; sync; shutdown -r +1&')
.and_return(obj)
handler.run_report_unsafe(status)
end
it 'resets run_list if node has a post_boot_runlist attribute' do
node.set['reboot-handler']['post_boot_runlist'] = ['role[foo]']
allow(node).to receive(:roles).and_return ['booted']
allow(node).to receive(:save)
node.run_state['reboot'] = true
handler.run_report_unsafe(status)
expect(node.run_list.to_s).to eq 'role[foo]'
end
end
end