~ubuntu-branches/ubuntu/lucid/puppet/lucid-security

« back to all changes in this revision

Viewing changes to test/ral/providers/cron/crontab.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
require 'puppettest/fileparsing'
8
8
 
9
9
class TestCronParsedProvider < Test::Unit::TestCase
10
 
        include PuppetTest
11
 
        include PuppetTest::FileParsing
 
10
    include PuppetTest
 
11
    include PuppetTest::FileParsing
12
12
 
13
13
 
14
14
    FIELDS = {
21
21
 
22
22
    # These are potentially multi-line records; there's no one-to-one map, but they model
23
23
    # a full cron job.  These tests assume individual record types will always be correctly
24
 
    # parsed, so all they 
 
24
    # parsed, so all they
25
25
    def sample_crons
26
26
        unless defined? @sample_crons
27
27
            @sample_crons = YAML.load(File.read(File.join(@crondir, "crontab_collections.yaml")))
221
221
            assert_nothing_raised("could not load %s" % file) do
222
222
                str, args = YAML.load(File.read(file))
223
223
            end
224
 
            
 
224
 
225
225
            # Stupid old yaml
226
226
            args.each do |hash|
227
227
                hash.each do |param, value|
298
298
        assert_equal("# Puppet Name: #{name}\n30 * * * * date > /dev/null", str,
299
299
            "Cron did not generate correctly")
300
300
    end
301
 
    
 
301
 
302
302
    # Test that comments are correctly retained
303
303
    def test_retain_comments
304
304
        str = "# this is a comment\n#and another comment\n"
380
380
        setme
381
381
 
382
382
        target = @provider.target_object(@me)
383
 
        
 
383
 
384
384
        [
385
385
            "* * * * * /some/command",
386
386
            "0,30 * * * * /some/command",
435
435
 
436
436
        # Now make some crons that should match
437
437
        matchers = [
438
 
            @type.create(
 
438
            @type.new(
439
439
                :name => "yaycron",
440
440
                :minute => [0, 30],
441
441
                :command => "date",
442
442
                :user => @me
443
443
            ),
444
 
            @type.create(
 
444
            @type.new(
445
445
                :name => "youtest",
446
446
                :command => "yaytest",
447
447
                :user => you
449
449
        ]
450
450
 
451
451
        nonmatchers = [
452
 
            @type.create(
 
452
            @type.new(
453
453
                :name => "footest",
454
454
                :minute => [0, 30],
455
455
                :hour => 1,
456
456
                :command => "fooness",
457
457
                :user => @me # wrong target
458
458
            ),
459
 
            @type.create(
 
459
            @type.new(
460
460
                :name => "funtest2",
461
461
                :command => "funtest",
462
462
                :user => you # wrong target for this cron
464
464
        ]
465
465
 
466
466
        # Create another cron so we prefetch two of them
467
 
        @type.create(:name => "testing", :minute => 30, :command => "whatever", :user => "you")
 
467
        @type.new(:name => "testing", :minute => 30, :command => "whatever", :user => "you")
468
468
 
469
469
        assert_nothing_raised("Could not prefetch cron") do
470
470
            @provider.prefetch([matchers, nonmatchers].flatten.inject({}) { |crons, cron| crons[cron.name] = cron; crons })
522
522
        setme
523
523
 
524
524
        target = @provider.target_object(@me)
525
 
        
 
525
 
526
526
        [
527
527
            "@daily /some/command",
528
528
            "@daily /some/command more"
555
555
    end
556
556
 
557
557
    def test_prefetch
558
 
        cron = @type.create :command => "/bin/echo yay", :name => "test", :hour => 4
 
558
        cron = @type.new :command => "/bin/echo yay", :name => "test", :hour => 4
559
559
 
560
560
        assert_nothing_raised("Could not prefetch cron") do
561
561
            cron.provider.class.prefetch("test" => cron)
570
570
        target = @provider.target_object(@me)
571
571
 
572
572
        # First with no env settings
573
 
        resource = @type.create :command => "/bin/echo yay", :name => "test", :hour => 4
 
573
        resource = @type.new :command => "/bin/echo yay", :name => "test", :hour => 4
574
574
        cron = resource.provider
575
575
 
576
576
        cron.ensure = :present