summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorSean Clemmer <sclemmer@bluejeans.com>2014-07-30 14:35:50 -0700
committerBryan McLellan <btm@getchef.com>2014-08-18 08:14:28 -0700
commit6e7d39ba920c79866cb162f08260cb904641327e (patch)
treed021fd309ffa55892181268c5d2035aecbe0f719 /spec
parente231f4399e65da25dd6f3a9f9357fdc60ed8c553 (diff)
downloadchef-6e7d39ba920c79866cb162f08260cb904641327e.tar.gz
Update cron resource spec to ensure duplicate entries are not created
Diffstat (limited to 'spec')
-rw-r--r--spec/functional/resource/cron_spec.rb21
1 files changed, 20 insertions, 1 deletions
diff --git a/spec/functional/resource/cron_spec.rb b/spec/functional/resource/cron_spec.rb
index 4c20023d78..0a19fae0ed 100644
--- a/spec/functional/resource/cron_spec.rb
+++ b/spec/functional/resource/cron_spec.rb
@@ -29,10 +29,14 @@ describe Chef::Resource::Cron, :requires_root, :unix_only do
case ohai[:platform]
when "aix", "solaris", "opensolaris", "solaris2", "omnios"
expect(shell_out("crontab -l #{new_resource.user} | grep \"#{cron_name}\"").exitstatus).to eq(0)
+ expect(shell_out("crontab -l #{new_resource.user} | grep \"#{cron_name}\"").stdout.lines.to_a.size).to eq(1)
expect(shell_out("crontab -l #{new_resource.user} | grep \"#{command}\"").exitstatus).to eq(0)
+ expect(shell_out("crontab -l #{new_resource.user} | grep \"#{command}\"").stdout.lines.to_a.size).to eq(1)
else
expect(shell_out("crontab -l -u #{new_resource.user} | grep \"#{cron_name}\"").exitstatus).to eq(0)
+ expect(shell_out("crontab -l #{new_resource.user} | grep \"#{cron_name}\"").stdout.lines.to_a.size).to eq(0)
expect(shell_out("crontab -l -u #{new_resource.user} | grep \"#{command}\"").exitstatus).to eq(0)
+ expect(shell_out("crontab -l #{new_resource.user} | grep \"#{command}\"").stdout.lines.to_a.size).to eq(0)
end
end
@@ -40,8 +44,10 @@ describe Chef::Resource::Cron, :requires_root, :unix_only do
case ohai[:platform]
when "aix", "solaris", "opensolaris", "solaris2", "omnios"
expect(shell_out("crontab -l #{new_resource.user} | grep \"#{cron_name}\"").exitstatus).to eq(1)
+ expect(shell_out("crontab -l #{new_resource.user} | grep \"#{new_resource.command}\"").stdout.lines.to_a.size).to eq(0)
else
expect(shell_out("crontab -l -u #{new_resource.user} | grep \"#{cron_name}\"").exitstatus).to eq(1)
+ expect(shell_out("crontab -l -u #{new_resource.user} | grep \"#{new_resource.command}\"").stdout.lines.to_a.size).to eq(0)
end
end
@@ -49,7 +55,11 @@ describe Chef::Resource::Cron, :requires_root, :unix_only do
let(:new_resource) do
new_resource = Chef::Resource::Cron.new("Chef functional test cron", run_context)
new_resource.user 'root'
- new_resource.minute "30"
+ new_resource.minute '@hourly'
+ new_resource.hour ''
+ new_resource.day ''
+ new_resource.month ''
+ new_resource.weekday ''
new_resource.command "/bin/true"
new_resource
end
@@ -68,6 +78,11 @@ describe Chef::Resource::Cron, :requires_root, :unix_only do
new_resource.run_action(:create)
cron_should_exists(new_resource.name, new_resource.command)
end
+
+ it "should create exactly one crontab entry" do
+ 5.times { new_resource.run_action(:create) }
+ cron_should_exists(new_resource.name, new_resource.command)
+ end
end
describe "delete action" do
@@ -128,6 +143,10 @@ describe Chef::Resource::Cron, :requires_root, :unix_only do
end
describe "negative tests for create action" do
+ after do
+ new_resource.run_action(:delete)
+ end
+
def cron_create_should_raise_exception
expect { new_resource.run_action(:create) }.to raise_error(Chef::Exceptions::Cron, /Error updating state of #{new_resource.name}, exit: 1/)
cron_should_not_exists(new_resource.name)