summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorVasu1105 <vasundhara.jagdale@msystechnologies.com>2017-12-19 09:43:53 +0000
committerVasu1105 <vasundhara.jagdale@msystechnologies.com>2018-01-05 06:38:55 +0000
commitaefec12e4657657b1227af0be373c1644cddbe1e (patch)
tree3fb0e4f57aa2535f47abbc8a7bb632eeb818b7d9 /spec
parent7fd821058fb94d708e8f2fdc95b26823c1ef92b2 (diff)
downloadchef-aefec12e4657657b1227af0be373c1644cddbe1e.tar.gz
Added new specs and updated code to handle more scenarios
Signed-off-by: Vasu1105 <vasundhara.jagdale@msystechnologies.com>
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/provider/windows_task_spec.rb94
-rw-r--r--spec/unit/resource/windows_task_spec.rb2
2 files changed, 95 insertions, 1 deletions
diff --git a/spec/unit/provider/windows_task_spec.rb b/spec/unit/provider/windows_task_spec.rb
index ce0fe9e50e..f06d847b17 100644
--- a/spec/unit/provider/windows_task_spec.rb
+++ b/spec/unit/provider/windows_task_spec.rb
@@ -620,4 +620,98 @@ describe Chef::Provider::WindowsTask do
expect(provider.send(:frequency_modifier_allowed)).to be(false)
end
end
+
+ # In windows_task resource sec_to_dur method converts seconds to duration in format 60 == 'PT60S'
+ # random_delay_updated? method use the value return by sec_to_dur as input for comparison for new_resource.random_delay mocking the same here
+ describe "#random_delay_updated?" do
+ before do
+ new_resource.command "chef-client"
+ new_resource.run_level :highest
+ new_resource.frequency :minute
+ new_resource.frequency_modifier 15
+ new_resource.user "SYSTEM"
+ end
+
+ it "returns false if current_resource.random_delay = nil & random_delay is set to '0' seconds" do
+ task_hash[:random_delay] = nil
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
+ provider.load_current_resource
+ new_resource.random_delay = 'PT0S'
+ expect(provider.send(:random_delay_updated?)).to be(false)
+ end
+
+ it "returns false if current_resource.random_delay = 'P7D' & random_delay is set to '604800' seconds " do
+ task_hash[:random_delay] = 'P7D'
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
+ provider.load_current_resource
+ new_resource.random_delay = 'PT604800S'
+ expect(provider.send(:random_delay_updated?)).to be(false)
+ end
+
+ it "returns false if current_resource.random_delay = 'P7DT1S' & random_delay is set to '604801' seconds" do
+ task_hash[:random_delay] = 'P7DT1S'
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
+ provider.load_current_resource
+ new_resource.random_delay = 'PT604801S'
+ expect(provider.send(:random_delay_updated?)).to be(false)
+ end
+
+ it "returns true if current_resource.random_delay = 'PT1S' & random_delay is set to '3600' seconds" do
+ task_hash[:random_delay] = 'PT1S'
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
+ provider.load_current_resource
+ new_resource.random_delay = 'PT3600S'
+ expect(provider.send(:random_delay_updated?)).to be(true)
+ end
+
+ it "returns false if current_resource.random_delay = 'P2Y1MT2H' & random_delay is set to '65707200' seconds" do
+ task_hash[:random_delay] = 'P2Y1MT2H'
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
+ provider.load_current_resource
+ new_resource.random_delay = 'PT65707200S'
+ expect(provider.send(:random_delay_updated?)).to be(false)
+ end
+ end
+
+ describe "#execution_time_limit_updated?" do
+ before do
+ new_resource.command "chef-client"
+ new_resource.run_level :highest
+ new_resource.frequency :minute
+ new_resource.frequency_modifier 15
+ new_resource.user "SYSTEM"
+ end
+
+ it "returns false if current_resource.execution_time_limit = 'P7D' & execution_time_limit is set to 604800 seconds " do
+ task_hash[:execution_time_limit] = 'P7D'
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
+ provider.load_current_resource
+ new_resource.execution_time_limit = 'PT604800S'
+ expect(provider.send(:execution_time_limit_updated?)).to be(false)
+ end
+
+ it "returns false if current_resource.execution_time_limit = 'P7DT1S' & execution_time_limit is set to 604801 seconds" do
+ task_hash[:execution_time_limit] = 'P7DT1S'
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
+ provider.load_current_resource
+ new_resource.execution_time_limit = 'PT604801S'
+ expect(provider.send(:execution_time_limit_updated?)).to be(false)
+ end
+
+ it "returns true if current_resource.execution_time_limit = 'PT1S' & execution_time_limit is set to '3600' seconds" do
+ task_hash[:execution_time_limit] = 'PT1S'
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
+ provider.load_current_resource
+ new_resource.execution_time_limit = 'PT3600S'
+ expect(provider.send(:execution_time_limit_updated?)).to be(true)
+ end
+
+ it "returns false if current_resource.execution_time_limit = 'P2Y1MT2H' & execution_time_limit is set to '65707200' seconds" do
+ task_hash[:execution_time_limit] = 'P2Y1MT2H'
+ allow(provider).to receive(:load_task_hash).and_return(task_hash)
+ provider.load_current_resource
+ new_resource.execution_time_limit = 'PT65707200S'
+ expect(provider.send(:execution_time_limit_updated?)).to be(false)
+ end
+ end
end
diff --git a/spec/unit/resource/windows_task_spec.rb b/spec/unit/resource/windows_task_spec.rb
index a40e143a49..f9349ad9bd 100644
--- a/spec/unit/resource/windows_task_spec.rb
+++ b/spec/unit/resource/windows_task_spec.rb
@@ -282,7 +282,7 @@ describe Chef::Resource::WindowsTask do
context "#sec_to_dur" do
it "return nil when passed 0" do
- expect(resource.send(:sec_to_dur, 0)).to eql(nil)
+ expect(resource.send(:sec_to_dur, 0)).to eql('PT0S')
end
it "return PT1S when passed 1" do
expect(resource.send(:sec_to_dur, 1)).to eql("PT1S")