Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/facter/cron_provider.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Fact: cron_provider
#
# Purpose: Returns the default provider Puppet will choose to manage cron
# on this system
#
# Resolution: Instantiates a dummy cron resource and return the provider
#
# Caveats:
#
require 'puppet/type'
require 'puppet/type/cron'

Facter.add(:cron_provider) do
setcode do
provider = Puppet::Type.type(:cron).newcron(name: 'dummy')[:provider]
provider.to_s if provider
end
end
29 changes: 29 additions & 0 deletions spec/unit/facter/cron_provider_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'
require 'puppet/type'
require 'puppet/type/cron'

describe 'cron_provider', type: :fact do
before(:each) { Facter.clear }
after(:each) { Facter.clear }

subject { Facter.fact(:cron_provider) }

it { is_expected.not_to be_nil }

context 'when available' do
it 'returns crontab' do
provider = Puppet::Type.type(:cron).provider(:crontab)
allow(Puppet::Type.type(:cron)).to receive(:defaultprovider).and_return(provider)

expect(subject.value).to eq('crontab')
end
end

context 'when unavailable' do
it 'returns nil' do
allow(Puppet::Type.type(:cron)).to receive(:defaultprovider).and_return(nil)

expect(subject.value).to be_nil
end
end
end