summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2017-12-07 13:58:46 -0800
committerTim Smith <tsmith@chef.io>2017-12-07 13:58:46 -0800
commitdb320dc818b36a24b01c267517bd087e8b0a3fb6 (patch)
tree7cea7421aceda962d6de0ff30230f8ed8c7bbce9
parent6cf225b7e4b9e3cb788e3998d4c54f32e55ea9df (diff)
downloadchef-db320dc818b36a24b01c267517bd087e8b0a3fb6.tar.gz
Add tests for invalid dates
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--spec/unit/resource/windows_task_spec.rb23
1 files changed, 21 insertions, 2 deletions
diff --git a/spec/unit/resource/windows_task_spec.rb b/spec/unit/resource/windows_task_spec.rb
index 21de8c6fb6..f16e29fd08 100644
--- a/spec/unit/resource/windows_task_spec.rb
+++ b/spec/unit/resource/windows_task_spec.rb
@@ -167,10 +167,29 @@ describe Chef::Resource::WindowsTask do
end
context "#validate_start_day" do
- it "raise error if start_day is passed with frequency :on_logon" do
- resource.frequency :on_logon
+ it "raise error if start_day is passed with invalid frequency (:on_logon)" do
expect { resource.send(:validate_start_day, "02/07/1984", :on_logon) }.to raise_error(Chef::Exceptions::ArgumentError, "`start_day` property is not supported with frequency: on_logon")
end
+
+ it "does not raise error if start_day is passed with valid frequency (:weekly)" do
+ expect { resource.send(:validate_start_day, "02/07/1984", :weekly) }.not_to raise_error
+ end
+
+ it "raise error if start_day is passed with invalid date format (DD/MM/YYYY)" do
+ expect { resource.send(:validate_start_day, "28/12/2009", :weekly) }.to raise_error(Chef::Exceptions::ArgumentError, "`start_day` property must be in the MM/DD/YYYY format.")
+ end
+
+ it "raise error if start_day is passed with invalid date format (M/DD/YYYY)" do
+ expect { resource.send(:validate_start_day, "2/07/1984", :weekly) }.to raise_error(Chef::Exceptions::ArgumentError, "`start_day` property must be in the MM/DD/YYYY format.")
+ end
+
+ it "raise error if start_day is passed with invalid date format (MM/D/YYYY)" do
+ expect { resource.send(:validate_start_day, "02/7/1984", :weekly) }.to raise_error(Chef::Exceptions::ArgumentError, "`start_day` property must be in the MM/DD/YYYY format.")
+ end
+
+ it "raise error if start_day is passed with invalid date format (MM/DD/YY)" do
+ expect { resource.send(:validate_start_day, "02/07/84", :weekly) }.to raise_error(Chef::Exceptions::ArgumentError, "`start_day` property must be in the MM/DD/YYYY format.")
+ end
end
context "#validate_interactive_setting" do