From a2af7dd0b9713f279724d2c7e6f17bfd8ce2d95b Mon Sep 17 00:00:00 2001 From: Jorie Tappa Date: Tue, 31 Jul 2018 14:56:46 -0500 Subject: Initial cron import from puppet 7a4c5f07bdf61a7bc7aa32a50e99489a604eac52 --- .../provider/cron/crontab/create_normal_entry | 19 ++ .../provider/cron/crontab/create_special_entry | 18 ++ .../provider/cron/crontab/crontab_user1 | 15 ++ .../provider/cron/crontab/crontab_user2 | 4 + .../integration/provider/cron/crontab/modify_entry | 13 + .../provider/cron/crontab/moved_cronjob_input1 | 15 ++ .../provider/cron/crontab/moved_cronjob_input2 | 6 + .../integration/provider/cron/crontab/purged | 8 + .../provider/cron/crontab/remove_named_resource | 12 + .../provider/cron/crontab/remove_unnamed_resource | 14 ++ .../provider/cron/crontab/unspecialized | 15 ++ .../unit/provider/cron/crontab/single_line.yaml | 272 +++++++++++++++++++++ .../unit/provider/cron/crontab/vixie_header.txt | 3 + spec/fixtures/unit/provider/cron/parsed/managed | 6 + spec/fixtures/unit/provider/cron/parsed/simple | 9 + 15 files changed, 429 insertions(+) create mode 100644 spec/fixtures/integration/provider/cron/crontab/create_normal_entry create mode 100644 spec/fixtures/integration/provider/cron/crontab/create_special_entry create mode 100644 spec/fixtures/integration/provider/cron/crontab/crontab_user1 create mode 100644 spec/fixtures/integration/provider/cron/crontab/crontab_user2 create mode 100644 spec/fixtures/integration/provider/cron/crontab/modify_entry create mode 100644 spec/fixtures/integration/provider/cron/crontab/moved_cronjob_input1 create mode 100644 spec/fixtures/integration/provider/cron/crontab/moved_cronjob_input2 create mode 100644 spec/fixtures/integration/provider/cron/crontab/purged create mode 100644 spec/fixtures/integration/provider/cron/crontab/remove_named_resource create mode 100644 spec/fixtures/integration/provider/cron/crontab/remove_unnamed_resource create mode 100644 spec/fixtures/integration/provider/cron/crontab/unspecialized create mode 100644 spec/fixtures/unit/provider/cron/crontab/single_line.yaml create mode 100644 spec/fixtures/unit/provider/cron/crontab/vixie_header.txt create mode 100644 spec/fixtures/unit/provider/cron/parsed/managed create mode 100644 spec/fixtures/unit/provider/cron/parsed/simple (limited to 'spec/fixtures') diff --git a/spec/fixtures/integration/provider/cron/crontab/create_normal_entry b/spec/fixtures/integration/provider/cron/crontab/create_normal_entry new file mode 100644 index 0000000..e3e2c04 --- /dev/null +++ b/spec/fixtures/integration/provider/cron/crontab/create_normal_entry @@ -0,0 +1,19 @@ +# HEADER: some simple +# HEADER: header +@daily /bin/unnamed_special_command >> /dev/null 2>&1 + +# commend with blankline above and below + +17-19,22 0-23/2 * * 2 /bin/unnamed_regular_command + +# Puppet Name: My daily failure +MAILTO="" +@daily /bin/false +# Puppet Name: Monthly job +SHELL=/bin/sh +MAILTO=mail@company.com +15 14 1 * * $HOME/bin/monthly +# Puppet Name: new entry +MAILTO="" +SHELL=/bin/bash +12 * * * 2 /bin/new diff --git a/spec/fixtures/integration/provider/cron/crontab/create_special_entry b/spec/fixtures/integration/provider/cron/crontab/create_special_entry new file mode 100644 index 0000000..ee25954 --- /dev/null +++ b/spec/fixtures/integration/provider/cron/crontab/create_special_entry @@ -0,0 +1,18 @@ +# HEADER: some simple +# HEADER: header +@daily /bin/unnamed_special_command >> /dev/null 2>&1 + +# commend with blankline above and below + +17-19,22 0-23/2 * * 2 /bin/unnamed_regular_command + +# Puppet Name: My daily failure +MAILTO="" +@daily /bin/false +# Puppet Name: Monthly job +SHELL=/bin/sh +MAILTO=mail@company.com +15 14 1 * * $HOME/bin/monthly +# Puppet Name: new special entry +MAILTO=bob@company.com +@reboot echo "Booted" 1>&2 diff --git a/spec/fixtures/integration/provider/cron/crontab/crontab_user1 b/spec/fixtures/integration/provider/cron/crontab/crontab_user1 new file mode 100644 index 0000000..2c7d542 --- /dev/null +++ b/spec/fixtures/integration/provider/cron/crontab/crontab_user1 @@ -0,0 +1,15 @@ +# HEADER: some simple +# HEADER: header +@daily /bin/unnamed_special_command >> /dev/null 2>&1 + +# commend with blankline above and below + +17-19,22 0-23/2 * * 2 /bin/unnamed_regular_command + +# Puppet Name: My daily failure +MAILTO="" +@daily /bin/false +# Puppet Name: Monthly job +SHELL=/bin/sh +MAILTO=mail@company.com +15 14 1 * * $HOME/bin/monthly diff --git a/spec/fixtures/integration/provider/cron/crontab/crontab_user2 b/spec/fixtures/integration/provider/cron/crontab/crontab_user2 new file mode 100644 index 0000000..267e643 --- /dev/null +++ b/spec/fixtures/integration/provider/cron/crontab/crontab_user2 @@ -0,0 +1,4 @@ +# HEADER: some simple +# HEADER: header +# Puppet Name: some_unrelevant job +* * * * * /bin/true diff --git a/spec/fixtures/integration/provider/cron/crontab/modify_entry b/spec/fixtures/integration/provider/cron/crontab/modify_entry new file mode 100644 index 0000000..ed06fd4 --- /dev/null +++ b/spec/fixtures/integration/provider/cron/crontab/modify_entry @@ -0,0 +1,13 @@ +# HEADER: some simple +# HEADER: header +@daily /bin/unnamed_special_command >> /dev/null 2>&1 + +# commend with blankline above and below + +17-19,22 0-23/2 * * 2 /bin/unnamed_regular_command + +# Puppet Name: My daily failure +MAILTO="" +@daily /bin/false +# Puppet Name: Monthly job +@monthly /usr/bin/monthly diff --git a/spec/fixtures/integration/provider/cron/crontab/moved_cronjob_input1 b/spec/fixtures/integration/provider/cron/crontab/moved_cronjob_input1 new file mode 100644 index 0000000..2c7d542 --- /dev/null +++ b/spec/fixtures/integration/provider/cron/crontab/moved_cronjob_input1 @@ -0,0 +1,15 @@ +# HEADER: some simple +# HEADER: header +@daily /bin/unnamed_special_command >> /dev/null 2>&1 + +# commend with blankline above and below + +17-19,22 0-23/2 * * 2 /bin/unnamed_regular_command + +# Puppet Name: My daily failure +MAILTO="" +@daily /bin/false +# Puppet Name: Monthly job +SHELL=/bin/sh +MAILTO=mail@company.com +15 14 1 * * $HOME/bin/monthly diff --git a/spec/fixtures/integration/provider/cron/crontab/moved_cronjob_input2 b/spec/fixtures/integration/provider/cron/crontab/moved_cronjob_input2 new file mode 100644 index 0000000..0b68287 --- /dev/null +++ b/spec/fixtures/integration/provider/cron/crontab/moved_cronjob_input2 @@ -0,0 +1,6 @@ +# HEADER: some simple +# HEADER: header +# Puppet Name: some_unrelevant job +* * * * * /bin/true +# Puppet Name: My daily failure +@daily /bin/false diff --git a/spec/fixtures/integration/provider/cron/crontab/purged b/spec/fixtures/integration/provider/cron/crontab/purged new file mode 100644 index 0000000..b302836 --- /dev/null +++ b/spec/fixtures/integration/provider/cron/crontab/purged @@ -0,0 +1,8 @@ +# HEADER: some simple +# HEADER: header + +# commend with blankline above and below + + +# Puppet Name: only managed entry +* * * * * /bin/true diff --git a/spec/fixtures/integration/provider/cron/crontab/remove_named_resource b/spec/fixtures/integration/provider/cron/crontab/remove_named_resource new file mode 100644 index 0000000..e1c1716 --- /dev/null +++ b/spec/fixtures/integration/provider/cron/crontab/remove_named_resource @@ -0,0 +1,12 @@ +# HEADER: some simple +# HEADER: header +@daily /bin/unnamed_special_command >> /dev/null 2>&1 + +# commend with blankline above and below + +17-19,22 0-23/2 * * 2 /bin/unnamed_regular_command + +# Puppet Name: Monthly job +SHELL=/bin/sh +MAILTO=mail@company.com +15 14 1 * * $HOME/bin/monthly diff --git a/spec/fixtures/integration/provider/cron/crontab/remove_unnamed_resource b/spec/fixtures/integration/provider/cron/crontab/remove_unnamed_resource new file mode 100644 index 0000000..2dcbfe2 --- /dev/null +++ b/spec/fixtures/integration/provider/cron/crontab/remove_unnamed_resource @@ -0,0 +1,14 @@ +# HEADER: some simple +# HEADER: header +@daily /bin/unnamed_special_command >> /dev/null 2>&1 + +# commend with blankline above and below + + +# Puppet Name: My daily failure +MAILTO="" +@daily /bin/false +# Puppet Name: Monthly job +SHELL=/bin/sh +MAILTO=mail@company.com +15 14 1 * * $HOME/bin/monthly diff --git a/spec/fixtures/integration/provider/cron/crontab/unspecialized b/spec/fixtures/integration/provider/cron/crontab/unspecialized new file mode 100644 index 0000000..e6a4082 --- /dev/null +++ b/spec/fixtures/integration/provider/cron/crontab/unspecialized @@ -0,0 +1,15 @@ +# HEADER: some simple +# HEADER: header +@daily /bin/unnamed_special_command >> /dev/null 2>&1 + +# commend with blankline above and below + +17-19,22 0-23/2 * * 2 /bin/unnamed_regular_command + +# Puppet Name: My daily failure +MAILTO="" +* * * * * /bin/false +# Puppet Name: Monthly job +SHELL=/bin/sh +MAILTO=mail@company.com +15 14 1 * * $HOME/bin/monthly diff --git a/spec/fixtures/unit/provider/cron/crontab/single_line.yaml b/spec/fixtures/unit/provider/cron/crontab/single_line.yaml new file mode 100644 index 0000000..da2853e --- /dev/null +++ b/spec/fixtures/unit/provider/cron/crontab/single_line.yaml @@ -0,0 +1,272 @@ +--- +:longcommment: + :text: "# This is a comment" + :record: + :line: "# This is a comment" + :record_type: :comment +:special: + :text: "@hourly /bin/date" + :record: + :special: hourly + :command: /bin/date + :record_type: :crontab +:long_name: + :text: "# Puppet Name: long_name" + :record: + :line: "# Puppet Name: long_name" + :name: long_name + :record_type: :comment +:multiple_minutes: + :text: 5,15 * * * * /bin/date + :record: + :minute: + - "5" + - "15" + :command: /bin/date + :record_type: :crontab +:environment: + :text: ONE=TWO + :record: + :line: ONE=TWO + :record_type: :environment +:empty: + :text: "" + :record: + :line: "" + :record_type: :blank +:simple: + :text: "* * * * * /bin/date" + :record: + :command: /bin/date + :record_type: :crontab +:whitespace: + :text: " " + :record: + :line: " " + :record_type: :blank +:minute_and_hour: + :text: 5 15 * * * /bin/date + :record: + :minute: + - "5" + :hour: + - "15" + :command: /bin/date + :record_type: :crontab +:lowercase_environment: + :text: a=b + :record: + :line: a=b + :record_type: :environment +:special_with_spaces: + :text: "@daily /bin/echo testing" + :record: + :special: daily + :command: /bin/echo testing + :record_type: :crontab +:tabs: + :text: !binary | + CQ== + + :record: + :line: !binary | + CQ== + + :record_type: :blank +:multiple_minute_and_hour: + :text: 5,10 15,20 * * * /bin/date + :record: + :minute: + - "5" + - "10" + :hour: + - "15" + - "20" + :command: /bin/date + :record_type: :crontab +:name: + :text: "# Puppet Name: testing" + :record: + :line: "# Puppet Name: testing" + :name: testing + :record_type: :comment +:another_env: + :text: Testing=True + :record: + :line: Testing=True + :record_type: :environment +:shortcomment: + :text: "#" + :record: + :line: "#" + :record_type: :comment +:spaces_in_command: + :text: "* * * * * /bin/echo testing" + :record: + :command: /bin/echo testing + :record_type: :crontab +:fourth_env: + :text: True=False + :record: + :line: True=False + :record_type: :environment +:simple_with_minute: + :text: 5 * * * * /bin/date + :record: + :minute: + - "5" + :command: /bin/date + :record_type: :crontab +:spaces_in_command_with_times: + :text: 5,10 15,20 * * * /bin/echo testing + :record: + :minute: + - "5" + - "10" + :hour: + - "15" + - "20" + :command: /bin/echo testing + :record_type: :crontab +:name_with_spaces: + :text: "# Puppet Name: another name" + :record: + :line: "# Puppet Name: another name" + :name: another name + :record_type: :comment +--- +:longcommment: + :text: "# This is a comment" + :record: + :line: "# This is a comment" + :record_type: :comment +:special: + :text: "@hourly /bin/date" + :record: + :special: hourly + :command: /bin/date + :record_type: :crontab +:long_name: + :text: "# Puppet Name: long_name" + :record: + :line: "# Puppet Name: long_name" + :name: long_name + :record_type: :comment +:multiple_minutes: + :text: 5,15 * * * * /bin/date + :record: + :minute: + - "5" + - "15" + :command: /bin/date + :record_type: :crontab +:environment: + :text: ONE=TWO + :record: + :line: ONE=TWO + :record_type: :environment +:empty: + :text: "" + :record: + :line: "" + :record_type: :blank +:simple: + :text: "* * * * * /bin/date" + :record: + :command: /bin/date + :record_type: :crontab +:whitespace: + :text: " " + :record: + :line: " " + :record_type: :blank +:minute_and_hour: + :text: 5 15 * * * /bin/date + :record: + :minute: + - "5" + :hour: + - "15" + :command: /bin/date + :record_type: :crontab +:lowercase_environment: + :text: a=b + :record: + :line: a=b + :record_type: :environment +:special_with_spaces: + :text: "@daily /bin/echo testing" + :record: + :special: daily + :command: /bin/echo testing + :record_type: :crontab +:tabs: + :text: !binary | + CQ== + + :record: + :line: !binary | + CQ== + + :record_type: :blank +:multiple_minute_and_hour: + :text: 5,10 15,20 * * * /bin/date + :record: + :minute: + - "5" + - "10" + :hour: + - "15" + - "20" + :command: /bin/date + :record_type: :crontab +:name: + :text: "# Puppet Name: testing" + :record: + :line: "# Puppet Name: testing" + :name: testing + :record_type: :comment +:another_env: + :text: Testing=True + :record: + :line: Testing=True + :record_type: :environment +:shortcomment: + :text: "#" + :record: + :line: "#" + :record_type: :comment +:spaces_in_command: + :text: "* * * * * /bin/echo testing" + :record: + :command: /bin/echo testing + :record_type: :crontab +:fourth_env: + :text: True=False + :record: + :line: True=False + :record_type: :environment +:simple_with_minute: + :text: 5 * * * * /bin/date + :record: + :minute: + - "5" + :command: /bin/date + :record_type: :crontab +:spaces_in_command_with_times: + :text: 5,10 15,20 * * * /bin/echo testing + :record: + :minute: + - "5" + - "10" + :hour: + - "15" + - "20" + :command: /bin/echo testing + :record_type: :crontab +:name_with_spaces: + :text: "# Puppet Name: another name" + :record: + :line: "# Puppet Name: another name" + :name: another name + :record_type: :comment diff --git a/spec/fixtures/unit/provider/cron/crontab/vixie_header.txt b/spec/fixtures/unit/provider/cron/crontab/vixie_header.txt new file mode 100644 index 0000000..7ccfc37 --- /dev/null +++ b/spec/fixtures/unit/provider/cron/crontab/vixie_header.txt @@ -0,0 +1,3 @@ +# DO NOT EDIT THIS FILE - edit the master and reinstall. +# (- installed on Thu Apr 12 12:16:01 2007) +# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $) diff --git a/spec/fixtures/unit/provider/cron/parsed/managed b/spec/fixtures/unit/provider/cron/parsed/managed new file mode 100644 index 0000000..c48d20a --- /dev/null +++ b/spec/fixtures/unit/provider/cron/parsed/managed @@ -0,0 +1,6 @@ +# Puppet Name: real_job +* * * * * /bin/true +# Puppet Name: complex_job +MAILTO=foo@example.com +SHELL=/bin/sh +@reboot /bin/true >> /dev/null 2>&1 diff --git a/spec/fixtures/unit/provider/cron/parsed/simple b/spec/fixtures/unit/provider/cron/parsed/simple new file mode 100644 index 0000000..477553e --- /dev/null +++ b/spec/fixtures/unit/provider/cron/parsed/simple @@ -0,0 +1,9 @@ +# use /bin/sh to run commands, no matter what /etc/passwd says +SHELL=/bin/sh +# mail any output to `paul', no matter whose crontab this is +MAILTO=paul +# +# run five minutes after midnight, every day +5 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1 +# run at 2:15pm on the first of every month -- output mailed to paul +15 14 1 * * $HOME/bin/monthly -- cgit v1.2.3 From 96d65f6d51da6b4798c81a717fb1a0d68c4c90e1 Mon Sep 17 00:00:00 2001 From: Jorie Tappa Date: Wed, 1 Aug 2018 11:27:33 -0500 Subject: Fix RSpec/RepeatedExample violations --- .../integration/provider/cron/crontab/crontab_user3 | 17 +++++++++++++++++ spec/integration/provider/cron/crontab_spec.rb | 6 +++--- spec/unit/provider/cron/parsed_spec.rb | 10 +--------- spec/unit/type/cron_spec.rb | 2 +- 4 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 spec/fixtures/integration/provider/cron/crontab/crontab_user3 (limited to 'spec/fixtures') diff --git a/spec/fixtures/integration/provider/cron/crontab/crontab_user3 b/spec/fixtures/integration/provider/cron/crontab/crontab_user3 new file mode 100644 index 0000000..ae314ae --- /dev/null +++ b/spec/fixtures/integration/provider/cron/crontab/crontab_user3 @@ -0,0 +1,17 @@ +# HEADER: some simple +# HEADER: header +@daily /bin/unnamed_special_command >> /dev/null 2>&1 + +# commend with blankline above and below + +17-19,22 0-23/2 * * 2 /bin/unnamed_regular_command + +# Puppet Name: My daily failure +MAILTO="" +@daily /bin/false +# Puppet Name: Monthly job +SHELL=/bin/sh +MAILTO=mail@company.com +15 14 1 * * $HOME/bin/monthly +# Puppet Name: My weekly failure +@weekly /bin/false diff --git a/spec/integration/provider/cron/crontab_spec.rb b/spec/integration/provider/cron/crontab_spec.rb index 0148d0c..c9661e4 100644 --- a/spec/integration/provider/cron/crontab_spec.rb +++ b/spec/integration/provider/cron/crontab_spec.rb @@ -136,13 +136,13 @@ describe Puppet::Type.type(:cron).provider(:crontab), '(integration)', unless: P it "works correctly when managing 'target' but not 'user'" do apply_with_error_check(<<-MANIFEST) cron { - 'My daily failure': - special => 'daily', + 'My weekly failure': + special => 'weekly', command => '/bin/false', target => '#{crontab_user1}', } MANIFEST - expect_output('crontab_user1') + expect_output('crontab_user3') end it 'does nothing if a matching entry already present' do diff --git a/spec/unit/provider/cron/parsed_spec.rb b/spec/unit/provider/cron/parsed_spec.rb index 8d6e282..d4460f7 100644 --- a/spec/unit/provider/cron/parsed_spec.rb +++ b/spec/unit/provider/cron/parsed_spec.rb @@ -194,18 +194,10 @@ describe Puppet::Type.type(:cron).provider(:crontab) do Facter.stubs(:value).with(:operatingsystem) end - it 'contains no resources for a user who has no crontab' do + it 'contains no resources for a user who has no crontab, or for a user that is absent' do # `crontab...` does only capture stdout here. On vixie-cron-4.1 # STDERR shows "no crontab for foobar" but stderr is ignored as # well as the exitcode. - described_class.target_object('foobar').expects(:`).with('crontab -u foobar -l 2>/dev/null').returns '' - expect(described_class.instances.select do |resource| - resource.get('target') == 'foobar' - end).to be_empty - end - - it 'contains no resources for a user who is absent' do - # `crontab...` does only capture stdout. On vixie-cron-4.1 # STDERR shows "crontab: user `foobar' unknown" but stderr is # ignored as well as the exitcode described_class.target_object('foobar').expects(:`).with('crontab -u foobar -l 2>/dev/null').returns '' diff --git a/spec/unit/type/cron_spec.rb b/spec/unit/type/cron_spec.rb index e80ccb9..f60468a 100644 --- a/spec/unit/type/cron_spec.rb +++ b/spec/unit/type/cron_spec.rb @@ -46,7 +46,7 @@ describe Puppet::Type.type(:cron), unless: Puppet.features.microsoft_windows? do end it 'supports absent as a value for ensure' do - expect { described_class.new(name: 'foo', ensure: :present) }.not_to raise_error + expect { described_class.new(name: 'foo', ensure: :absent) }.not_to raise_error end it 'does not support other values' do -- cgit v1.2.3