diff options
-rw-r--r-- | lib/chef/resource/windows_task.rb | 6 | ||||
-rw-r--r-- | spec/unit/resource/windows_task_spec.rb | 8 |
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/chef/resource/windows_task.rb b/lib/chef/resource/windows_task.rb index 14f5da46fa..c2439797df 100644 --- a/lib/chef/resource/windows_task.rb +++ b/lib/chef/resource/windows_task.rb @@ -82,7 +82,7 @@ class Chef validate_create_frequency_modifier(frequency, frequency_modifier) validate_create_day(day, frequency) if day validate_create_months(months, frequency) if months - validate_idle_time(idle_time, frequency) if idle_time + validate_idle_time(idle_time, frequency) if idle_time.nil? || !(idle_time > 0 && idle_time <= 999) end private @@ -199,7 +199,9 @@ class Chef unless [:on_idle].include?(frequency) raise ArgumentError, "idle_time property is only valid for tasks that run on_idle" end - + if idle_time.nil? + raise ArgumentError, "idle_time value should be set for :on_idle frequency." + end unless idle_time > 0 && idle_time <= 999 raise ArgumentError, "idle_time value #{idle_time} is invalid. Valid values for :on_idle frequency are 1 - 999." end diff --git a/spec/unit/resource/windows_task_spec.rb b/spec/unit/resource/windows_task_spec.rb index 145063b53e..18a4960d90 100644 --- a/spec/unit/resource/windows_task_spec.rb +++ b/spec/unit/resource/windows_task_spec.rb @@ -278,6 +278,14 @@ describe Chef::Resource::WindowsTask do it "raises error if idle_time > 999" do expect { resource.send(:validate_idle_time, 1000, :on_idle) }.to raise_error(ArgumentError, "idle_time value 1000 is invalid. Valid values for :on_idle frequency are 1 - 999.") end + + it "raises error if idle_time < 0" do + expect { resource.send(:validate_idle_time, -5, :on_idle) }.to raise_error(ArgumentError, "idle_time value -5 is invalid. Valid values for :on_idle frequency are 1 - 999.") + end + + it "raises error if idle_time is not set" do + expect { resource.send(:validate_idle_time, nil, :on_idle) }.to raise_error(ArgumentError, "idle_time value should be set for :on_idle frequency.") + end end context "#sec_to_dur" do |