summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Doherty <cdoherty@getchef.com>2014-09-03 16:13:47 -0700
committerChris Doherty <cdoherty@getchef.com>2014-09-10 16:34:17 -0700
commitb33f55c555a68d559f32b216c18d25c5b8cb80ac (patch)
treea3245df4529e8242218616484e908212f9e6ef84
parent32f7f6526e07053ba972129883eb016caf3ca731 (diff)
downloadchef-b33f55c555a68d559f32b216c18d25c5b8cb80ac.tar.gz
Add spec/functional/resource/reboot_spec.rb.
-rw-r--r--spec/functional/resource/reboot_spec.rb75
1 files changed, 75 insertions, 0 deletions
diff --git a/spec/functional/resource/reboot_spec.rb b/spec/functional/resource/reboot_spec.rb
new file mode 100644
index 0000000000..eed521c41e
--- /dev/null
+++ b/spec/functional/resource/reboot_spec.rb
@@ -0,0 +1,75 @@
+#
+# 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::Resource::Reboot do
+
+ let(:expected) do
+ {
+ :delay_mins => 5,
+ :requested_by => "reboot resource functional test",
+ :reason => "reboot resource spec test"
+ }
+ end
+
+ def create_resource
+ node = Chef::Node.new
+ events = Chef::EventDispatch::Dispatcher.new
+ run_context = Chef::RunContext.new(node, {}, events)
+ resource = Chef::Resource::Reboot.new(expected[:requested_by], run_context)
+ resource.delay_mins(expected[:delay_mins])
+ resource.reason(expected[:reason])
+ resource
+ end
+
+ let(:resource) do
+ create_resource
+ end
+
+ # TODO: decide on a behavior for multiple :request and/or :cancel calls, and test for it.
+
+ describe "the request action" do
+ before do
+ resource.run_action(:request)
+ end
+
+ after do
+ resource.run_context.cancel_reboot
+ 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])
+ end
+ end
+
+ describe "the cancel action" do
+ before do
+ resource.run_context.request_reboot(expected)
+ resource.run_action(:cancel)
+ end
+
+ it 'should have cleared the run context reboot data' do
+ expect(resource.run_context.reboot_info).to eq({})
+ end
+ end
+end