aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDorin Pleava <dorin.pleava@puppet.com>2020-08-06 15:14:37 +0300
committerDorin Pleava <dorin.pleava@puppet.com>2020-08-10 15:44:35 +0300
commit29925fb28a09075ea4c4105674dca2415e1c7800 (patch)
treead4a5ceeadc4d8b6e01b12c81bc4d8d94ae638a3 /spec
parent7cc67bf30ca7462ab9be0142673b27e271dcb258 (diff)
downloadpuppet-cron_core-29925fb28a09075ea4c4105674dca2415e1c7800.tar.gz
puppet-cron_core-29925fb28a09075ea4c4105674dca2415e1c7800.tar.bz2
(MODULES-7786) Allow leading zeroes for cron params
When applying a cron manigest that contains leading zeroes in a periodic attribute (hour, minute, month, monthday, weekday), puppet will strip down the zeroes even if they are accepted by the system cron. Now puppet will only convert to integer the periodic attributes when validating them, but will not change the input from the manifest.
Diffstat (limited to 'spec')
-rw-r--r--spec/acceptance/tests/resource/cron/should_write_leading_zeroes_spec.rb31
-rw-r--r--spec/unit/type/cron_spec.rb45
2 files changed, 76 insertions, 0 deletions
diff --git a/spec/acceptance/tests/resource/cron/should_write_leading_zeroes_spec.rb b/spec/acceptance/tests/resource/cron/should_write_leading_zeroes_spec.rb
new file mode 100644
index 0000000..eb2bf1e
--- /dev/null
+++ b/spec/acceptance/tests/resource/cron/should_write_leading_zeroes_spec.rb
@@ -0,0 +1,31 @@
+require 'spec_helper_acceptance'
+
+RSpec.context 'when leading zeroes are present' do
+ before(:each) do
+ compatible_agents.each do |agent|
+ step 'ensure the user exists via puppet'
+ setup(agent)
+ end
+ end
+
+ after(:each) do
+ compatible_agents.each do |agent|
+ step 'Cron: cleanup'
+ clean(agent)
+ end
+ end
+
+ compatible_agents.each do |host|
+ it 'does not ignore leading zeroes' do
+ step 'apply the resource on the host' do
+ on(host, puppet_resource('cron', 'crontest', 'user=tstuser', 'command=/bin/true', 'ensure=present', "minute='05'", "hour='007'", "weekday='03'", "month='0011'", "monthday='07'"), acceptable_exit_codes: [0])
+ end
+
+ step 'Verify that crontab -l contains what you expected' do
+ run_cron_on(host, :list, 'tstuser') do
+ expect(stdout).to match(%r{05 007 07 0011 03 /bin/true})
+ end
+ end
+ end
+ end
+end
diff --git a/spec/unit/type/cron_spec.rb b/spec/unit/type/cron_spec.rb
index 32bde11..1ce66a4 100644
--- a/spec/unit/type/cron_spec.rb
+++ b/spec/unit/type/cron_spec.rb
@@ -127,6 +127,15 @@ describe Puppet::Type.type(:cron), unless: Puppet.features.microsoft_windows? do
# As it turns out cron does not complaining about steps that exceed the valid range
# expect { described_class.new(:name => 'foo', :minute => '*/120' ) }.to raise_error(Puppet::Error, /is not a valid minute/)
end
+
+ it 'supports values with leading zeros' do
+ expect { described_class.new(name: 'foo', minute: ['0', '0011', '044']) }.not_to raise_error
+ expect { described_class.new(name: 'foo', minute: '022') }.not_to raise_error
+ end
+
+ it 'does not remove leading zeroes' do
+ expect(described_class.new(name: 'foo', minute: '0045')[:minute]).to eq(['0045'])
+ end
end
describe 'hour' do
@@ -194,6 +203,15 @@ describe Puppet::Type.type(:cron), unless: Puppet.features.microsoft_windows? do
# As it turns out cron does not complaining about steps that exceed the valid range
# expect { described_class.new(:name => 'foo', :hour => '*/26' ) }.to raise_error(Puppet::Error, /is not a valid hour/)
end
+
+ it 'supports values with leading zeros' do
+ expect { described_class.new(name: 'foo', hour: ['007', '1', '0023']) }.not_to raise_error
+ expect { described_class.new(name: 'foo', hour: '022') }.not_to raise_error
+ end
+
+ it 'does not remove leading zeroes' do
+ expect(described_class.new(name: 'foo', hour: '005')[:hour]).to eq(['005'])
+ end
end
describe 'weekday' do
@@ -277,6 +295,15 @@ describe Puppet::Type.type(:cron), unless: Puppet.features.microsoft_windows? do
# As it turns out cron does not complaining about steps that exceed the valid range
# expect { described_class.new(:name => 'foo', :weekday => '*/9' ) }.to raise_error(Puppet::Error, /is not a valid weekday/)
end
+
+ it 'supports values with leading zeros' do
+ expect { described_class.new(name: 'foo', weekday: ['Mon', 'Wed', '05']) }.not_to raise_error
+ expect { described_class.new(name: 'foo', weekday: '007') }.not_to raise_error
+ end
+
+ it 'does not remove leading zeroes' do
+ expect(described_class.new(name: 'foo', weekday: '006')[:weekday]).to eq(['006'])
+ end
end
describe 'month' do
@@ -376,6 +403,15 @@ describe Puppet::Type.type(:cron), unless: Puppet.features.microsoft_windows? do
# As it turns out cron does not complaining about steps that exceed the valid range
# expect { described_class.new(:name => 'foo', :month => '*/13' ) }.to raise_error(Puppet::Error, /is not a valid month/)
end
+
+ it 'supports values with leading zeros' do
+ expect { described_class.new(name: 'foo', month: ['007', '1', '0012']) }.not_to raise_error
+ expect { described_class.new(name: 'foo', month: ['Jan', '04', '0009']) }.not_to raise_error
+ end
+
+ it 'does not remove leading zeroes' do
+ expect(described_class.new(name: 'foo', month: '09')[:month]).to eq(['09'])
+ end
end
describe 'monthday' do
@@ -441,6 +477,15 @@ describe Puppet::Type.type(:cron), unless: Puppet.features.microsoft_windows? do
# As it turns out cron does not complaining about steps that exceed the valid range
# expect { described_class.new(:name => 'foo', :monthday => '*/32' ) }.to raise_error(Puppet::Error, /is not a valid monthday/)
end
+
+ it 'supports values with leading zeros' do
+ expect { described_class.new(name: 'foo', monthday: ['007', '1', '0023']) }.not_to raise_error
+ expect { described_class.new(name: 'foo', monthday: '022') }.not_to raise_error
+ end
+
+ it 'does not remove leading zeroes' do
+ expect(described_class.new(name: 'foo', monthday: '01')[:monthday]).to eq(['01'])
+ end
end
describe 'special' do