diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/functional/resource/windows_task_spec.rb | 306 |
1 files changed, 304 insertions, 2 deletions
diff --git a/spec/functional/resource/windows_task_spec.rb b/spec/functional/resource/windows_task_spec.rb index b9aa6c6568..0c3fd5cb38 100644 --- a/spec/functional/resource/windows_task_spec.rb +++ b/spec/functional/resource/windows_task_spec.rb @@ -18,6 +18,7 @@ require "spec_helper" require "chef/provider/windows_task" +require "byebug" describe Chef::Resource::WindowsTask, :windows_only do let(:task_name) { "chef-client" } @@ -31,7 +32,6 @@ describe Chef::Resource::WindowsTask, :windows_only do describe "action :create" do after { delete_task } - context "when frequency and frequency_modifier are not passed" do subject do new_resource = Chef::Resource::WindowsTask.new(task_name, run_context) @@ -51,6 +51,12 @@ describe Chef::Resource::WindowsTask, :windows_only do # This test will not work across locales expect(task_details[:StartDate]).to eq("9/20/2017") end + + it "does not converge the resource if it is already converged" do + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end end context "frequency :minute" do @@ -71,6 +77,12 @@ describe Chef::Resource::WindowsTask, :windows_only do expect(task_details[:"Repeat:Every"]).to eq("0 Hour(s), 15 Minute(s)") expect(task_details[:run_level]).to eq("HighestAvailable") end + + it "does not converge the resource if it is already converged" do + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end end context "frequency :hourly" do @@ -91,6 +103,12 @@ describe Chef::Resource::WindowsTask, :windows_only do expect(task_details[:"Repeat:Every"]).to eq("3 Hour(s), 0 Minute(s)") expect(task_details[:run_level]).to eq("HighestAvailable") end + + it "does not converge the resource if it is already converged" do + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end end context "frequency :daily" do @@ -111,6 +129,12 @@ describe Chef::Resource::WindowsTask, :windows_only do expect(task_details[:Days]).to eq("Every 1 day(s)") expect(task_details[:run_level]).to eq("HighestAvailable") end + + it "does not converge the resource if it is already converged" do + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end end context "frequency :monthly" do @@ -132,6 +156,13 @@ describe Chef::Resource::WindowsTask, :windows_only do expect(task_details[:Months]).to eq("FEB, APR, JUN, AUG, OCT, DEC") expect(task_details[:run_level]).to eq("HighestAvailable") end + + it "does not converge the resource if it is already converged" do + skip "This functionality needs to be handle" + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end end context "frequency :once" do @@ -160,6 +191,13 @@ describe Chef::Resource::WindowsTask, :windows_only do expect(task_details[:StartTime]).to eq("5:00:00 PM") expect(task_details[:run_level]).to eq("HighestAvailable") end + + it "does not converge the resource if it is already converged" do + subject.start_time "17:00" + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end end end @@ -169,7 +207,6 @@ describe Chef::Resource::WindowsTask, :windows_only do new_resource.command task_name new_resource.run_level :highest new_resource.frequency :none - new_resource.random_delay "" new_resource end @@ -186,6 +223,42 @@ describe Chef::Resource::WindowsTask, :windows_only do expect(task_details[:none]).to eq(true) expect(task_details[:run_level]).to eq("HighestAvailable") end + + it "does not converge the resource if it is already converged" do + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end + end + + context "frequency :onstart" 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.frequency :onstart + new_resource + end + + it "creates the scheduled task to run at system start up" do + subject.run_action(:create) + task_details = windows_task_provider.send(:load_task_hash, task_name) + + expect(task_details[:TaskName]).to eq("\\chef-client") + expect(task_details[:TaskToRun]).to eq("chef-client") + expect(task_details[:ScheduleType]).to eq("At system start up") + expect(task_details[:StartTime]).to eq("N/A") + expect(task_details[:StartDate]).to eq("N/A") + expect(task_details[:NextRunTime]).to eq("N/A") + expect(task_details[:onstart]).to eq(true) + expect(task_details[:run_level]).to eq("HighestAvailable") + end + + it "does not converge the resource if it is already converged" do + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end end context "frequency :weekly" do @@ -207,6 +280,13 @@ describe Chef::Resource::WindowsTask, :windows_only do expect(task_details[:run_level]).to eq("HighestAvailable") end + it "does not converge the resource if it is already converged" do + skip "This functionality needs to be handle" + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end + context "when days are provided" do it "creates the scheduled task to run on particular days" do subject.day "Mon, Fri" @@ -220,6 +300,14 @@ describe Chef::Resource::WindowsTask, :windows_only do expect(task_details[:Months]).to eq("Every 2 week(s)") expect(task_details[:run_level]).to eq("HighestAvailable") end + + it "does not converge the resource if it is already converged" do + subject.day "Mon, Fri" + subject.frequency_modifier 2 + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end end context "when invalid day is passed" do @@ -254,6 +342,12 @@ describe Chef::Resource::WindowsTask, :windows_only do expect(task_details[:ScheduleType]).to eq("At logon time") expect(task_details[:run_level]).to eq("HighestAvailable") end + + it "does not converge the resource if it is already converged" do + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end end context "frequency :on_idle" do @@ -282,6 +376,13 @@ describe Chef::Resource::WindowsTask, :windows_only do expect(task_details[:run_level]).to eq("HighestAvailable") expect(task_details[:idle_time]).to eq("PT20M") end + + it "does not converge the resource if it is already converged" do + subject.idle_time 20 + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end end end @@ -305,6 +406,14 @@ describe Chef::Resource::WindowsTask, :windows_only do expect(task_details[:random_delay]).to eq("PT20M") end + it "does not converge the resource if it is already converged" do + subject.frequency :minute + subject.random_delay "PT20M" + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end + it "raises error if invalid random_delay is passed" do subject.frequency :minute subject.random_delay "abc" @@ -319,6 +428,192 @@ describe Chef::Resource::WindowsTask, :windows_only do end end + describe "Examples of idempotent checks for each frequency" do + after { delete_task } + context "For frequency :once" 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.frequency :once + new_resource.start_time "17:00" + new_resource + end + + it "create task by adding frequency_modifier as 1" do + subject.frequency_modifier 1 + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end + + it "create task by adding frequency_modifier as 5" do + skip "This functionality needs to be handle" + subject.frequency_modifier 5 + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end + end + + context "For frequency :none" 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.frequency :none + new_resource + end + + it "create task by adding frequency_modifier as 1" do + subject.frequency_modifier 1 + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end + + it "create task by adding frequency_modifier as 5" do + skip "This functionality needs to be handle" + subject.frequency_modifier 5 + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end + end + + context "For frequency :weekly" 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.frequency :weekly + new_resource + end + + it "create task by adding start_day" do + skip "This functionality needs to be handle" + subject.start_day '12/28/2018' + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end + + it "create task by adding frequency_modifier and random_delay" do + skip "This functionality needs to be handle" + subject.frequency_modifier 3 + subject.random_delay '60' + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end + end + + context "For frequency :monthly" 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.frequency :once + new_resource.start_time "17:00" + new_resource + end + + it "create task by adding frequency_modifier as 1" do + subject.frequency_modifier 1 + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end + + it "create task by adding frequency_modifier as 5" do + skip "This functionality needs to be handle" + subject.frequency_modifier 5 + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end + end + + context "For frequency :hourly" 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.frequency :hourly + new_resource.frequency_modifier 5 + new_resource.random_delay '2400' + new_resource + end + + it "create task by adding frequency_modifier and random_delay" do + skip "This functionality needs to be handle" + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end + end + + context "For frequency :daily" 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.frequency :daily + new_resource.frequency_modifier 2 + new_resource.random_delay '2400' + new_resource + end + + it "create task by adding frequency_modifier and random_delay" do + skip "This functionality needs to be handle" + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end + end + + context "For frequency :on_logon" do + subject do + new_resource = Chef::Resource::WindowsTask.new(task_name, run_context) + new_resource.command task_name + new_resource.frequency :on_logon + new_resource + end + + it "create task by adding frequency_modifier and random_delay" do + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end + + it "create task by adding frequency_modifier as 5" do + skip "This functionality needs to be handle" + subject.frequency_modifier 5 + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end + end + + context "For frequency :onstart" 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.frequency :onstart + new_resource.frequency_modifier 20 + new_resource + end + + it "create task by adding frequency_modifier as 20" do + skip "This functionality needs to be handle" + subject.run_action(:create) + subject.run_action(:create) + expect(subject).not_to be_updated_by_last_action + end + end + end + describe "#after_created" do subject do new_resource = Chef::Resource::WindowsTask.new(task_name, run_context) @@ -397,6 +692,13 @@ describe Chef::Resource::WindowsTask, :windows_only do task_details = windows_task_provider.send(:load_task_hash, task_name) expect(task_details).to eq(false) end + + it "does not converge the resource if it is already converged" do + subject.run_action(:create) + subject.run_action(:delete) + subject.run_action(:delete) + expect(subject).not_to be_updated_by_last_action + end end describe "action :run" do |