Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'maint-refactor_cron_filetype_selection'

  • Loading branch information...
commit ca35b9b73e8eeaac73766716b1f9d4b5fba4158c 2 parents 0d01204 + 6f1c3dc
@adrienthebo adrienthebo authored
View
26 lib/puppet/provider/cron/crontab.rb
@@ -1,17 +1,6 @@
require 'puppet/provider/parsedfile'
-tab = case Facter.value(:osfamily)
- when "Solaris"
- :suntab
- when "AIX"
- :aixtab
- else
- :crontab
- end
-
-
-
-Puppet::Type.type(:cron).provide(:crontab, :parent => Puppet::Provider::ParsedFile, :default_target => ENV["USER"] || "root", :filetype => tab) do
+Puppet::Type.type(:cron).provide(:crontab, :parent => Puppet::Provider::ParsedFile, :default_target => ENV["USER"] || "root") do
commands :crontab => "crontab"
text_line :comment, :match => %r{^\s*#}, :post_parse => proc { |record|
@@ -22,6 +11,19 @@
text_line :environment, :match => %r{^\s*\w+=}
+ def self.filetype
+ tabname = case Facter.value(:osfamily)
+ when "Solaris"
+ :suntab
+ when "AIX"
+ :aixtab
+ else
+ :crontab
+ end
+
+ Puppet::Util::FileType.filetype(tabname)
+ end
+
self::TIME_FIELDS = [:minute, :hour, :monthday, :month, :weekday]
record_line :crontab,
View
16 spec/unit/provider/cron/parsed_spec.rb
@@ -56,18 +56,19 @@
}
end
- # I am not able to stub operatingsystem because the filetype is determined
- # at load time
describe "when determining the correct filetype" do
- it "should use the suntab filetype on Solaris", :if => Facter.value(:operatingsystem) == 'Solaris' do
+ it "should use the suntab filetype on Solaris" do
+ Facter.stubs(:value).with(:osfamily).returns 'Solaris'
described_class.filetype.should == Puppet::Util::FileType::FileTypeSuntab
end
- it "should use the aixtab filetype on AIX", :if => Facter.value(:operatingsystem) == 'AIX' do
+ it "should use the aixtab filetype on AIX" do
+ Facter.stubs(:value).with(:osfamily).returns 'AIX'
described_class.filetype.should == Puppet::Util::FileType::FileTypeAixtab
end
- it "should use the crontab filetype on other platforms", :unless => %w{AIX Solaris}.include?(Facter.value(:operatingsystem)) do
+ it "should use the crontab filetype on other platforms" do
+ Facter.stubs(:value).with(:osfamily).returns 'Not a real operating system family'
described_class.filetype.should == Puppet::Util::FileType::FileTypeCrontab
end
end
@@ -176,6 +177,11 @@
end
describe "on linux" do
+ before do
+ Facter.stubs(:value).with(:osfamily).returns 'Linux'
+ Facter.stubs(:value).with(:operatingsystem)
+ end
+
it "should be empty if user has no crontab" do
# `crontab...` does only capture stdout here. On vixie-cron-4.1
# STDERR shows "no crontab for foobar" but stderr is ignored as
Please sign in to comment.
Something went wrong with that request. Please try again.