From e49408174d1e7662bd18f088accd8cc33d0e152c Mon Sep 17 00:00:00 2001 From: Enis Inan Date: Sat, 1 Dec 2018 16:35:32 -0800 Subject: (MODULES-8306) Port over the crontab filetypes from Puppet --- spec/unit/provider/cron/parsed_spec.rb | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'spec/unit/provider/cron/parsed_spec.rb') diff --git a/spec/unit/provider/cron/parsed_spec.rb b/spec/unit/provider/cron/parsed_spec.rb index d54129c..b115f9d 100644 --- a/spec/unit/provider/cron/parsed_spec.rb +++ b/spec/unit/provider/cron/parsed_spec.rb @@ -64,17 +64,17 @@ describe Puppet::Type.type(:cron).provider(:crontab) do describe 'when determining the correct filetype' do it 'uses the suntab filetype on Solaris' do Facter.stubs(:value).with(:osfamily).returns 'Solaris' - expect(described_class.filetype).to eq(Puppet::Util::FileType::FileTypeSuntab) + expect(described_class.filetype).to eq(Puppet::Provider::Cron::FileType::FileTypeSuntab) end it 'uses the aixtab filetype on AIX' do Facter.stubs(:value).with(:osfamily).returns 'AIX' - expect(described_class.filetype).to eq(Puppet::Util::FileType::FileTypeAixtab) + expect(described_class.filetype).to eq(Puppet::Provider::Cron::FileType::FileTypeAixtab) end it 'uses the crontab filetype on other platforms' do Facter.stubs(:value).with(:osfamily).returns 'Not a real operating system family' - expect(described_class.filetype).to eq(Puppet::Util::FileType::FileTypeCrontab) + expect(described_class.filetype).to eq(Puppet::Provider::Cron::FileType::FileTypeCrontab) end end @@ -194,20 +194,25 @@ 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, or for a user that is absent' do - if Puppet.version.to_f < 5.0 - described_class.target_object('foobar').expects(:`).with('crontab -u foobar -l 2>/dev/null').returns '' - else - Puppet::Util::Execution - .expects(:execute) - .with('crontab -u foobar -l', failonfail: true, combine: true) - .returns('') - end + it 'contains no resources for a user who has no crontab' do + Puppet::Util.stubs(:uid).returns(10) + + Puppet::Util::Execution + .expects(:execute) + .with('crontab -u foobar -l', failonfail: true, combine: true) + .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 + Puppet::Util.stubs(:uid).returns(nil) + + expect(described_class.instances).to be_empty + end + it 'is able to create records from not-managed records' do described_class.stubs(:target_object).returns File.new(my_fixture('simple')) parameters = described_class.instances.map do |p| -- cgit v1.2.3