aboutsummaryrefslogtreecommitdiff
path: root/spec/unit/type
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/unit/type
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/unit/type')
-rw-r--r--spec/unit/type/cron_spec.rb45
1 files changed, 45 insertions, 0 deletions
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