diff options
author | Bryan McLellan <btm@loftninjas.org> | 2018-01-08 10:58:33 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-08 10:58:33 -0500 |
commit | b694b10886eafcc2526d1ab1eae600d037d93c86 (patch) | |
tree | 152ccf6f6cf0baa47b6657b2720d196d9476141c /spec | |
parent | 6962aed89f88ede2503f7e171308e0f0d006ba89 (diff) | |
parent | 1a7fe48b1158a04ce354416d27fc70d81c82b670 (diff) | |
download | chef-b694b10886eafcc2526d1ab1eae600d037d93c86.tar.gz |
Merge pull request #6688 from MsysTechnologiesllc/vasundhara/chef#6638_windows_task_not_fully_idempotent
Fix windows_task resource not being idempotent for random_delay and execution_time_limit
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/provider/windows_task_spec.rb | 94 | ||||
-rw-r--r-- | spec/unit/resource/windows_task_spec.rb | 18 |
2 files changed, 103 insertions, 9 deletions
diff --git a/spec/unit/provider/windows_task_spec.rb b/spec/unit/provider/windows_task_spec.rb index ce0fe9e50e..a71ce92f56 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 fe0c55ecaf..145063b53e 100644 --- a/spec/unit/resource/windows_task_spec.rb +++ b/spec/unit/resource/windows_task_spec.rb @@ -281,23 +281,23 @@ describe Chef::Resource::WindowsTask do end context "#sec_to_dur" do - it "return PT0S when passed 0" do + it "return nil when passed 0" do 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") end - it "return PT24H0S when passed 86400" do - expect(resource.send(:sec_to_dur, 86400)).to eql("PT24H0S") + it "return PT86400S when passed 86400" do + expect(resource.send(:sec_to_dur, 86400)).to eql("PT86400S") end - it "return P1DT1S when passed 86401" do - expect(resource.send(:sec_to_dur, 86401)).to eql("P1DT1S") + it "return PT86401S when passed 86401" do + expect(resource.send(:sec_to_dur, 86401)).to eql("PT86401S") end - it "return P1DT1M40S when passed 86500" do - expect(resource.send(:sec_to_dur, 86500)).to eql("P1DT1M40S") + it "return PT86500S when passed 86500" do + expect(resource.send(:sec_to_dur, 86500)).to eql("PT86500S") end - it "return P1WT1S when passed 604801" do - expect(resource.send(:sec_to_dur, 604801)).to eql("P1WT1S") + it "return PT604801S when passed 604801" do + expect(resource.send(:sec_to_dur, 604801)).to eql("PT604801S") end end end |