diff options
author | Tim Smith <tsmith@chef.io> | 2018-08-20 11:50:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-20 11:50:30 -0700 |
commit | a220e94a2a10fc5bc6e54dae2b2f39459d6605fc (patch) | |
tree | 79ed96cbb67549424dfafd4dcfb0ac09f137cc40 /spec | |
parent | a67a82745ac1a72df21d1b6145374c3c19ef64a3 (diff) | |
parent | d00357daa06cf6300d21962566311f121c64d415 (diff) | |
download | chef-a220e94a2a10fc5bc6e54dae2b2f39459d6605fc.tar.gz |
Merge pull request #7483 from MsysTechnologiesllc/dh/MSYS-854_support_task_on_battery
Support for battery power options in windows_task resource
Diffstat (limited to 'spec')
-rw-r--r-- | spec/functional/resource/windows_task_spec.rb | 84 | ||||
-rw-r--r-- | spec/unit/resource/windows_task_spec.rb | 8 |
2 files changed, 92 insertions, 0 deletions
diff --git a/spec/functional/resource/windows_task_spec.rb b/spec/functional/resource/windows_task_spec.rb index 02c84d5229..a2cd4b97d7 100644 --- a/spec/functional/resource/windows_task_spec.rb +++ b/spec/functional/resource/windows_task_spec.rb @@ -1096,6 +1096,90 @@ describe Chef::Resource::WindowsTask, :windows_only do end end + context "when battery options are passed" do + subject do + new_resource = Chef::Resource::WindowsTask.new(task_name, run_context) + new_resource.command task_name + new_resource.run_level :highest + new_resource.execution_time_limit = 259200 / 60 # converting "PT72H" into minutes and passing here since win32-taskscheduler accespts this + new_resource + end + + it "sets the default if options are not provided" do + subject.frequency :minute + call_for_create_action + # loading current resource again to check new task is created and it matches task parameters + current_resource = call_for_load_current_resource + expect(current_resource.exists).to eq(true) + expect(current_resource.stop_if_going_on_batteries).to eql(false) + expect(current_resource.disallow_start_if_on_batteries).to eql(false) + end + + it "sets disallow_start_if_on_batteries to true" do + subject.frequency :minute + subject.disallow_start_if_on_batteries true + call_for_create_action + # loading current resource again to check new task is created and it matches task parameters + current_resource = call_for_load_current_resource + expect(current_resource.exists).to eq(true) + expect(current_resource.task.settings[:disallow_start_if_on_batteries]).to eql(true) + end + + it "sets disallow_start_if_on_batteries to false" do + subject.frequency :minute + subject.disallow_start_if_on_batteries false + call_for_create_action + # loading current resource again to check new task is created and it matches task parameters + current_resource = call_for_load_current_resource + expect(current_resource.exists).to eq(true) + expect(current_resource.task.settings[:disallow_start_if_on_batteries]).to eql(false) + end + + it "sets stop_if_going_on_batteries to true" do + subject.frequency :minute + subject.stop_if_going_on_batteries true + call_for_create_action + # loading current resource again to check new task is creted and it matches task parameters + current_resource = call_for_load_current_resource + expect(current_resource.exists).to eq(true) + expect(current_resource.task.settings[:stop_if_going_on_batteries]).to eql(true) + end + + it "sets stop_if_going_on_batteries to false" do + subject.frequency :minute + subject.stop_if_going_on_batteries false + call_for_create_action + # loading current resource again to check new task is created and it matches task parameters + current_resource = call_for_load_current_resource + expect(current_resource.exists).to eq(true) + expect(current_resource.task.settings[:stop_if_going_on_batteries]).to eql(false) + end + + it "sets the default if options are nil" do + subject.frequency :minute + subject.stop_if_going_on_batteries nil + subject.disallow_start_if_on_batteries nil + call_for_create_action + # loading current resource again to check new task is created and it matches task parameters + current_resource = call_for_load_current_resource + expect(current_resource.exists).to eq(true) + expect(current_resource.task.settings[:stop_if_going_on_batteries]).to eql(false) + expect(current_resource.task.settings[:disallow_start_if_on_batteries]).to eql(false) + end + + it "does not converge the resource if it is already converged" do + subject.frequency :minute + subject.stop_if_going_on_batteries true + subject.disallow_start_if_on_batteries false + subject.run_action(:create) + subject.frequency :minute + subject.stop_if_going_on_batteries true + subject.disallow_start_if_on_batteries false + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end + end + context "frequency :none" do subject do new_resource = Chef::Resource::WindowsTask.new(task_name, run_context) diff --git a/spec/unit/resource/windows_task_spec.rb b/spec/unit/resource/windows_task_spec.rb index cbf15092f5..76e2a86ee8 100644 --- a/spec/unit/resource/windows_task_spec.rb +++ b/spec/unit/resource/windows_task_spec.rb @@ -53,6 +53,14 @@ describe Chef::Resource::WindowsTask, :windows_only do expect(resource.frequency_modifier).to eql(1) end + it "sets the default value for disallow_start_if_on_batteries as false" do + expect(resource.disallow_start_if_on_batteries).to eql(false) + end + + it "sets the default value for stop_if_going_on_batteries as false" do + expect(resource.stop_if_going_on_batteries).to eql(false) + end + context "when frequency is not provided" do it "raises ArgumentError to provide frequency" do expect { resource.after_created }.to raise_error(ArgumentError, "Frequency needs to be provided. Valid frequencies are :minute, :hourly, :daily, :weekly, :monthly, :once, :on_logon, :onstart, :on_idle, :none." ) |