~nvalcarcel/ubuntu/lucid/puppet/fix-546677

« back to all changes in this revision

Viewing changes to test/ral/type/cron.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
# Test cron job creation, modification, and destruction
8
8
 
9
9
class TestCron < Test::Unit::TestCase
10
 
        include PuppetTest
 
10
    include PuppetTest
11
11
 
12
12
    def setup
13
13
        super
25
25
    def teardown
26
26
        super
27
27
        @crontype.defaultprovider = nil
28
 
        Puppet::Util::FileType.filetype(:ram).clear
29
28
    end
30
29
 
31
30
    def eachprovider
38
37
    def cronback
39
38
        tab = nil
40
39
        assert_nothing_raised {
41
 
            tab = Puppet.type(:cron).filetype.read(@me)
 
40
            tab = Puppet::Type.type(:cron).filetype.read(@me)
42
41
        }
43
42
 
44
43
        if $? == 0
78
77
            args = {:command => command, :name => name}
79
78
        end
80
79
        assert_nothing_raised {
81
 
            cron = @crontype.create(args)
 
80
            cron = @crontype.new(args)
82
81
        }
83
82
 
84
83
        return cron
125
124
            name = "yaytest"
126
125
            command = "date > /dev/null "
127
126
            assert_nothing_raised {
128
 
                cron = @crontype.create(
 
127
                cron = @crontype.new(
129
128
                    :name => name,
130
129
                    :command => "date > /dev/null ",
131
130
                    :month => "May",
145
144
                next unless prop.name.to_s == "command"
146
145
                assert(prop.insync?(value), "Property %s is not considered in sync with value %s" % [prop.name, value.inspect])
147
146
            end
148
 
 
149
 
            @crontype.clear
150
147
        end
151
148
    end
152
149
 
153
150
    def test_makeandretrievecron
154
151
        %w{storeandretrieve a-name another-name more_naming SomeName}.each do |name|
155
152
            cron = mkcron(name)
156
 
            comp = mk_catalog(name, cron)
157
 
            trans = assert_events([:cron_created], comp, name)
158
 
            
 
153
            catalog = mk_catalog(name, cron)
 
154
            trans = assert_events([:cron_created], catalog, name)
 
155
 
159
156
            cron.provider.class.prefetch
160
157
            cron = nil
161
158
 
162
 
            assert(cron = Puppet.type(:cron)[name], "Could not retrieve named cron")
163
 
            assert_instance_of(Puppet.type(:cron), cron)
 
159
            assert(cron = catalog.resource(:cron, name), "Could not retrieve named cron")
 
160
            assert_instance_of(Puppet::Type.type(:cron), cron)
164
161
        end
165
162
    end
166
163
 
174
171
            :weekday => {
175
172
                :valid => [ 0, 3, 6, "1", "tue", "wed",
176
173
                    "Wed", "MOnday", "SaTurday" ],
177
 
                :invalid => [ -1, 7, "13", "tues", "teusday", "thurs" ]
 
174
                :invalid => [ -1, 8, "13", "tues", "teusday", "thurs" ]
178
175
            },
179
176
            :hour => {
180
177
                :valid => [ 0, 21, 23 ],
197
194
            [:valid, :invalid].each { |type|
198
195
                hash[type].each { |value|
199
196
                    case type
200
 
                    when :valid:
 
197
                    when :valid
201
198
                        assert_nothing_raised {
202
199
                            cron[param] = value
203
200
                        }
206
203
                            assert_equal([value.to_s], cron.should(param),
207
204
                                "Cron value was not set correctly")
208
205
                        end
209
 
                    when :invalid:
 
206
                    when :invalid
210
207
                        assert_raise(Puppet::Error, "%s is incorrectly a valid %s" %
211
208
                            [value, param]) {
212
209
                            cron[param] = value
227
224
        eachprovider do |provider|
228
225
            cron = nil
229
226
            assert_nothing_raised {
230
 
                cron = @crontype.create(
 
227
                cron = @crontype.new(
231
228
                    :command => "/bin/date > /dev/null",
232
229
                    :minute => [0, 30],
233
230
                    :name => "crontest",
247
244
                next unless prop.name.to_s == "minute"
248
245
                assert(prop.insync?(value), "Property %s is not considered in sync with value %s" % [prop.name, value.inspect])
249
246
            end
250
 
            @crontype.clear
251
247
        end
252
248
    end
253
249
 
254
250
    def test_fieldremoval
255
251
        cron = nil
256
252
        assert_nothing_raised {
257
 
            cron = @crontype.create(
 
253
            cron = @crontype.new(
258
254
                :command => "/bin/date > /dev/null",
259
255
                :minute => [0, 30],
260
256
                :name => "crontest",
286
282
        cleanup { provider.filetype = ft }
287
283
 
288
284
        setme
289
 
        cron = @crontype.create(:name => "testing",
 
285
        cron = @crontype.new(:name => "testing",
290
286
            :minute => [0, 30],
291
287
            :command => "/bin/testing",
292
288
            :user => @me
294
290
        # Write it to our file
295
291
        assert_apply(cron)
296
292
 
297
 
        @crontype.clear
298
 
 
299
293
        crons = []
300
294
        assert_nothing_raised {
301
295
            @crontype.instances.each do |cron|
348
342
      unless param =~ /=$/
349
343
        param = "%s=" % param
350
344
      end
351
 
    
 
345
 
352
346
      cron.provider.send(param, value)
353
347
    end
354
348
 
430
424
        crons = []
431
425
        users = ["root", nonrootuser.name]
432
426
        users.each do |user|
433
 
            cron = Puppet::Type.type(:cron).create(
 
427
            cron = Puppet::Type.type(:cron).new(
434
428
                :name => "testcron-#{user}",
435
429
                :user => user,
436
430
                :command => "/bin/echo",
461
455
    def test_default_user
462
456
        crontab = @crontype.provider(:crontab)
463
457
        if crontab.suitable?
464
 
            inst = @crontype.create(
 
458
            inst = @crontype.new(
465
459
                :name => "something", :command => "/some/thing",
466
460
                :provider => :crontab)
467
461
            assert_equal(Etc.getpwuid(Process.uid).name, inst.should(:user),
471
465
 
472
466
            # Now make a new cron with a user, and make sure it gets copied
473
467
            # over
474
 
            inst = @crontype.create(:name => "yay", :command => "/some/thing",
 
468
            inst = @crontype.new(:name => "yay", :command => "/some/thing",
475
469
                :user => "bin", :provider => :crontab)
476
470
            assert_equal("bin", inst.should(:target),
477
471
                "target did not default to user with crontab")
481
475
    # #705 - make sure extra spaces don't screw things up
482
476
    def test_spaces_in_command
483
477
        string = "echo   multiple  spaces"
484
 
        cron = @crontype.create(:name => "space testing", :command => string)
 
478
        cron = @crontype.new(:name => "space testing", :command => string)
485
479
        assert_apply(cron)
486
480
 
487
 
        cron.class.clear
488
 
        cron = @crontype.create(:name => "space testing", :command => string)
 
481
        cron = @crontype.new(:name => "space testing", :command => string)
489
482
 
490
483
        # Now make sure that it's correctly in sync
491
484
        cron.provider.class.prefetch("testing" => cron)