summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2017-12-08 10:58:26 -0800
committerTim Smith <tsmith@chef.io>2017-12-08 10:58:26 -0800
commitd91dc1cce0efa2d00bfbe37ecbcd154500c99986 (patch)
tree3d7aebb865e52a932676374d2b30a9bb8c61d7dd
parent3ece60a594d9f176a28ea371d830d14c723fa99b (diff)
downloadchef-more_task.tar.gz
These are all input validation errors so they should raise ArgumentError not RuntimeErrormore_task
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/windows_task.rb12
-rw-r--r--spec/unit/resource/windows_task_spec.rb18
2 files changed, 14 insertions, 16 deletions
diff --git a/lib/chef/resource/windows_task.rb b/lib/chef/resource/windows_task.rb
index 07674675bb..b205a50a6b 100644
--- a/lib/chef/resource/windows_task.rb
+++ b/lib/chef/resource/windows_task.rb
@@ -179,20 +179,18 @@ class Chef
days = day.split(",")
days.each do |d|
unless ["mon", "tue", "wed", "thu", "fri", "sat", "sun", "*"].include?(d.strip.downcase)
- raise "day property invalid. Only valid values are: MON, TUE, WED, THU, FRI, SAT, SUN and *. Multiple values must be separated by a comma."
+ raise ArgumentError, "day property invalid. Only valid values are: MON, TUE, WED, THU, FRI, SAT, SUN and *. Multiple values must be separated by a comma."
end
end
end
end
def validate_create_months(months, frequency)
- unless [:monthly].include?(frequency)
- raise "months property is only valid for tasks that run monthly"
- end
+ raise ArgumentError, "months property is only valid for tasks that run monthly" unless frequency == :monthly
if months.is_a? String
months.split(",").each do |month|
unless ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC", "*"].include?(month.strip.upcase)
- raise "months property invalid. Only valid values are: JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC and *. Multiple values must be separated by a comma."
+ raise ArgumentError, "months property invalid. Only valid values are: JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC and *. Multiple values must be separated by a comma."
end
end
end
@@ -200,11 +198,11 @@ class Chef
def validate_idle_time(idle_time, frequency)
unless [:on_idle].include?(frequency)
- raise "idle_time property is only valid for tasks that run on_idle"
+ raise ArgumentError, "idle_time property is only valid for tasks that run on_idle"
end
unless idle_time > 0 && idle_time <= 999
- raise "idle_time value #{idle_time} is invalid. Valid values for :on_idle frequency are 1 - 999."
+ raise ArgumentError, "idle_time value #{idle_time} is invalid. Valid values for :on_idle frequency are 1 - 999."
end
end
diff --git a/spec/unit/resource/windows_task_spec.rb b/spec/unit/resource/windows_task_spec.rb
index a077a46ba5..5a132c9b90 100644
--- a/spec/unit/resource/windows_task_spec.rb
+++ b/spec/unit/resource/windows_task_spec.rb
@@ -70,12 +70,12 @@ describe Chef::Resource::WindowsTask do
it "does not raise an error if the user is a system user" do
resource.user 'NT AUTHORITY\SYSTEM'
- expect { resource.after_created }.to_not raise_error(ArgumentError)
+ expect { resource.after_created }.to_not raise_error
end
it "does not raise an error if the user is a system user even if lowercase" do
resource.user 'nt authority\system'
- expect { resource.after_created }.to_not raise_error(ArgumentError)
+ expect { resource.after_created }.to_not raise_error
end
end
@@ -248,35 +248,35 @@ describe Chef::Resource::WindowsTask do
end
it "raises error for invalid day value" do
- expect { resource.send(:validate_create_day, "xyz", :weekly) }.to raise_error(RuntimeError, "day property invalid. Only valid values are: MON, TUE, WED, THU, FRI, SAT, SUN and *. Multiple values must be separated by a comma.")
+ expect { resource.send(:validate_create_day, "xyz", :weekly) }.to raise_error(ArgumentError, "day property invalid. Only valid values are: MON, TUE, WED, THU, FRI, SAT, SUN and *. Multiple values must be separated by a comma.")
end
end
context "#validate_create_months" do
it "raises error if frequency is not :monthly" do
- expect { resource.send(:validate_create_months, "Jan", :once) }.to raise_error(RuntimeError, "months property is only valid for tasks that run monthly")
+ expect { resource.send(:validate_create_months, "Jan", :once) }.to raise_error(ArgumentError, "months property is only valid for tasks that run monthly")
end
it "accepts a valid single month" do
- expect { resource.send(:validate_create_months, "Feb", :monthly) }.not_to raise_error(ArgumentError)
+ expect { resource.send(:validate_create_months, "Feb", :monthly) }.not_to raise_error
end
it "accepts a comma separated list of valid months" do
- expect { resource.send(:validate_create_months, "Jan, mar, AUG", :monthly) }.not_to raise_error(ArgumentError)
+ expect { resource.send(:validate_create_months, "Jan, mar, AUG", :monthly) }.not_to raise_error
end
it "raises error for invalid month value" do
- expect { resource.send(:validate_create_months, "xyz", :monthly) }.to raise_error(RuntimeError, "months property invalid. Only valid values are: JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC and *. Multiple values must be separated by a comma.")
+ expect { resource.send(:validate_create_months, "xyz", :monthly) }.to raise_error(ArgumentError, "months property invalid. Only valid values are: JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC and *. Multiple values must be separated by a comma.")
end
end
context "#validate_idle_time" do
it "raises error if frequency is not :on_idle" do
- expect { resource.send(:validate_idle_time, 5, :hourly) }.to raise_error(RuntimeError, "idle_time property is only valid for tasks that run on_idle")
+ expect { resource.send(:validate_idle_time, 5, :hourly) }.to raise_error(ArgumentError, "idle_time property is only valid for tasks that run on_idle")
end
it "raises error if idle_time > 999" do
- expect { resource.send(:validate_idle_time, 1000, :on_idle) }.to raise_error(RuntimeError, "idle_time value 1000 is invalid. Valid values for :on_idle frequency are 1 - 999.")
+ 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
end