Showing with 120 additions and 9 deletions.
  1. +1 −1 .msync.yml
  2. +8 −0 CHANGELOG.md
  3. +5 −2 Gemfile
  4. +1 −1 metadata.json
  5. +78 −0 spec/defines/job_spec.rb
  6. +6 −1 types/date.pp
  7. +6 −1 types/hour.pp
  8. +5 −1 types/minute.pp
  9. +5 −1 types/month.pp
  10. +5 −1 types/weekday.pp
2 changes: 1 addition & 1 deletion .msync.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
modulesync_config_version: '1.9.2'
modulesync_config_version: '1.9.3'
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
Each new release typically also includes the latest modulesync defaults.
These should not affect the functionality of the module.

## [v1.3.0](https://github.com/voxpupuli/puppet-cron/tree/v1.3.0) (2018-07-15)

[Full Changelog](https://github.com/voxpupuli/puppet-cron/compare/v1.2.0...v1.3.0)

**Implemented enhancements:**

- Update data types to allow comma-delimited lists [\#50](https://github.com/voxpupuli/puppet-cron/pull/50) ([jcbollinger](https://github.com/jcbollinger))

## [v1.2.0](https://github.com/voxpupuli/puppet-cron/tree/v1.2.0) (2018-06-25)

[Full Changelog](https://github.com/voxpupuli/puppet-cron/compare/v1.1.1...v1.2.0)
Expand Down
7 changes: 5 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def location_for(place, fake_version = nil)
end

group :test do
gem 'puppetlabs_spec_helper', '~> 2.6.0', :require => false
gem 'puppetlabs_spec_helper', '~> 2.6', :require => false
gem 'rspec-puppet', '~> 2.5', :require => false
gem 'rspec-puppet-facts', :require => false
gem 'rspec-puppet-utils', :require => false
Expand Down Expand Up @@ -55,13 +55,16 @@ group :system_tests do
gem 'beaker-hostgenerator', '>= 1.1.10', :require => false
gem 'beaker-puppet_install_helper', :require => false
gem 'beaker-module_install_helper', :require => false
gem 'rbnacl', '~> 4', :require => false if RUBY_VERSION >= '2.2.6'
gem 'rbnacl-libsodium', :require => false if RUBY_VERSION >= '2.2.6'
gem 'bcrypt_pbkdf', :require => false
end

group :release do
gem 'github_changelog_generator', :require => false, :git => 'https://github.com/skywinder/github-changelog-generator' if RUBY_VERSION >= '2.2.2'
gem 'puppet-blacksmith', :require => false
gem 'voxpupuli-release', :require => false, :git => 'https://github.com/voxpupuli/voxpupuli-release-gem'
gem 'puppet-strings', '~> 1.0', :require => false
gem 'puppet-strings', '>= 1.0', :require => false
end


Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppet-cron",
"version": "1.2.0",
"version": "1.3.0",
"author": "Vox Pupuli",
"summary": "Module to manage cron jobs via /etc/cron.d/",
"license": "Apache-2.0",
Expand Down
78 changes: 78 additions & 0 deletions spec/defines/job_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,67 @@
require 'spec_helper'

describe 'cron::job' do
params_cases = {
'all minutes' => { minute: '*', should_accept: true },
'skip minutes' => { minute: '*/3', should_accept: true },
'integer minutes' => { minute: 31, should_accept: true },
'simple minutes list' => { minute: '1,2,17,42', should_accept: true },
'complex minutes list' => { minute: '1-2,5-15/3,42', should_accept: true },
'too-large minute' => { minute: 60, should_accept: false },
'too-small minute' => { minute: -1, should_accept: false },
'wildcard in minute list' => { minute: '*,3', should_accept: false },
'bad minute range start' => { minute: '-1-30', should_accept: false },
'bad minute range end' => { minute: '30-60', should_accept: false },
'bad minute range skip' => { minute: '1-59/0', should_accept: false },
'all hours' => { hour: '*', should_accept: true },
'skip hours' => { hour: '*/3', should_accept: true },
'integer hours' => { hour: 13, should_accept: true },
'simple hours list' => { hour: '1,2,12,23', should_accept: true },
'complex hours list' => { hour: '1-2,3-6/3,12', should_accept: true },
'too-large hour' => { hour: 24, should_accept: false },
'too-small hour' => { hour: -1, should_accept: false },
'wildcard in hour list' => { hour: '*,3', should_accept: false },
'bad hour range start' => { hour: '-1-13', should_accept: false },
'bad hour range end' => { hour: '12-24', should_accept: false },
'bad hour range skip' => { hour: '1-23/0', should_accept: false },
'all dates' => { date: '*', should_accept: true },
'skip dates' => { date: '*/3', should_accept: true },
'integer dates' => { date: 28, should_accept: true },
'simple dates list' => { date: '1,2,12,31', should_accept: true },
'complex dates list' => { date: '1-2,3-18/3,24', should_accept: true },
'too-large date' => { date: 32, should_accept: false },
'too-small date' => { date: 0, should_accept: false },
'wildcard in date list' => { date: '*,3', should_accept: false },
'bad date range start' => { date: '0-13', should_accept: false },
'bad date range end' => { date: '12-32', should_accept: false },
'bad date range skip' => { date: '1-30/0', should_accept: false },
'all months' => { month: '*', should_accept: true },
'skip months' => { month: '*/4', should_accept: true },
'integer months' => { month: 7, should_accept: true },
'simple months list' => { month: '1,5,7,12', should_accept: true },
'complex months list' => { month: '1-2,4-10/2,12', should_accept: true },
'too-large month' => { month: 13, should_accept: false },
'too-small month' => { month: 0, should_accept: false },
'wildcard in month list' => { month: '*,3', should_accept: false },
'bad month range start' => { month: '0-9', should_accept: false },
'bad month range end' => { month: '3-13', should_accept: false },
'bad month range skip' => { month: '1-12/0', should_accept: false },
'month name in list' => { month: '1,May,9', should_accept: false },
'month name in range' => { month: 'Jun-Aug', should_accept: false },
'all weekdays' => { weekday: '*', should_accept: true },
'skip weekdays' => { weekday: '*/3', should_accept: true },
'integer weekdays' => { weekday: 5, should_accept: true },
'simple weekdays list' => { weekday: '0,2,5,7', should_accept: true },
'complex weekdays list' => { weekday: '1-2,3-6/3,7', should_accept: true },
'too-large weekday' => { weekday: 8, should_accept: false },
'too-small weekday' => { weekday: -1, should_accept: false },
'wildcard in weekday list' => { weekday: '*,3', should_accept: false },
'bad weekday range start' => { weekday: '-1-7', should_accept: false },
'bad weekday range end' => { weekday: '2-8', should_accept: false },
'bad weekday range skip' => { weekday: '1-5/0', should_accept: false },
'day name in list' => { weekday: '1,Wed,6', should_accept: false },
'day name in range' => { weekday: 'Mon-Fri', should_accept: false }
}
let(:title) { 'mysql_backup' }

context 'job with default values' do
Expand Down Expand Up @@ -68,4 +129,21 @@
is_expected.to contain_file("job_#{title}").with('ensure' => 'absent')
end
end

# Multiple test cases for variations on time field values
params_cases.each do |desc, p|
context "job with #{desc}" do
let(:params) { p.reject { |k, _v| k == :should_accept } .update(command: '/bin/true') }
let(:cron_timestamp) { get_timestamp(params) }

if p[:should_accept]
it do
is_expected.to compile
is_expected.to contain_file("job_#{title}").with_content(%r{\n#{cron_timestamp}\s+})
end
else
it { is_expected.to compile.and_raise_error(%r{.*}) }
end
end
end
end
7 changes: 6 additions & 1 deletion types/date.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Valid $date (day of month) parameter to Cron::Job.
type Cron::Date = Variant[
Integer[1,31],
Pattern[/\A(([1-9]|[1-2][0-9]|3[0-1])|(\*|(([1-9]|[1-2][0-9]|3[0-1])-([1-9]|[1-2][0-9]|3[0-1])))(\/([1-9]|[1-2][0-9]|3[0-1]))?)\z/]
Pattern[/(?x)\A(
\* ( \/ ( [12][0-9]?|3[01]?|[4-9] ) )?
| ( [12][0-9]?|3[01]?|[4-9] ) ( - ( [12][0-9]?|3[01]?|[4-9] ) ( \/ ( [12][0-9]?|3[01]?|[4-9] ) )? )?
( , ( [12][0-9]?|3[01]?|[4-9] ) ( - ( [12][0-9]?|3[01]?|[4-9] ) ( \/ ( [12][0-9]?|3[01]?|[4-9] ) )? )? )*
)\z/]
]

7 changes: 6 additions & 1 deletion types/hour.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Valid $hour parameter to Cron::Job.
type Cron::Hour = Variant[
Integer[0,23],
Pattern[/\A(([0-9]|1[0-9]|2[0-3])|(\*|(([0-9]|1[0-9]|2[0-3])-([0-9]|1[0-9]|2[0-3])))(\/([1-9]|1[0-9]|2[0-3]))?)\z/]
Pattern[/(?x)\A(
\* ( \/ ( 1[0-9]|2[0-3]|[3-9] ) )?
| ( 1?[0-9]|2[0-3] ) ( - ( 1?[0-9]|2[0-3] ) ( \/ ( 1[0-9]|2[0-3]|[3-9] ) )? )?
( , ( 1?[0-9]|2[0-3] ) ( - ( 1?[0-9]|2[0-3] ) ( \/ ( 1[0-9]|2[0-3]|[3-9] ) )? )? )*
)\z/]
]

6 changes: 5 additions & 1 deletion types/minute.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Valid $minute parameter to Cron::Job.
type Cron::Minute = Variant[
Integer[0,59],
Pattern[/\A(([0-9]|[1-5][0-9])|(\*|(([0-9]|[1-5][0-9])-([0-9]|[1-5][0-9])))(\/([1-9]|[1-5][0-9]))?)\z/]
Pattern[/(?x)\A(
\* ( \/ ( [1-5][0-9]?|[6-9] ) )?
| [1-5]?[0-9] ( - [1-5]?[0-9] ( \/ ( [1-5][0-9]?|[6-9] ) )? )?
( , [1-5]?[0-9] ( - [1-5]?[0-9] ( \/ ( [1-5][0-9]?|[6-9] ) )? )? )*
)\z/]
]
6 changes: 5 additions & 1 deletion types/month.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
type Cron::Month = Variant[
Cron::Monthname,
Integer[1,12],
Pattern[/\A(([1-9]|1[0-2])|(\*|(([1-9]|1[0-2])-([1-9]|1[0-2])))(\/([1-9]|1[0-2]))?)\z/]
Pattern[/(?x)\A(
\* ( \/ ( 1[012]?|[2-9] ) )?
| ( 1[012]?|[2-9] ) ( - ( 1[012]?|[2-9] ) ( \/ ( 1[012]?|[2-9] ) )? )?
( , ( 1[012]?|[2-9] ) ( - ( 1[012]?|[2-9] ) ( \/ ( 1[012]?|[2-9] ) )? )? )*
)\z/]
]
6 changes: 5 additions & 1 deletion types/weekday.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
type Cron::Weekday = Variant[
Cron::Weekdayname,
Integer[0,7],
Pattern[/\A([0-7]|(\*|([0-7]-[0-7]))(\/[1-7])?)\z/]
Pattern[/(?x)\A(
\* ( \/ [1-7] )?
| [0-7] ( - [0-7] ( \/ [1-7] )? )?
( , [0-7] ( - [0-7] ( \/ [1-7] )? )? )*
)\z/]
]