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

« back to all changes in this revision

Viewing changes to test/network/handler/runner.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:
3
3
require File.dirname(__FILE__) + '/../../lib/puppettest'
4
4
 
5
5
require 'puppettest'
 
6
require 'puppet/network/handler/runner'
6
7
 
7
8
class TestHandlerRunner < Test::Unit::TestCase
8
 
        include PuppetTest
9
 
 
10
 
    def mkclient(code)
11
 
        master = nil
12
 
        client = nil
13
 
        Puppet[:code] = code
14
 
        # create our master
15
 
        assert_nothing_raised() {
16
 
            # this is the default server setup
17
 
            master = Puppet::Network::Handler.master.new(
18
 
                :Local => true
19
 
            )
20
 
        }
21
 
 
22
 
        # and our client
23
 
        assert_nothing_raised() {
24
 
            client = Puppet::Network::Client.master.new(
25
 
                :Master => master
26
 
            )
27
 
        }
28
 
 
29
 
        client
30
 
    end
31
 
 
32
 
    def setup
33
 
        super
34
 
        FileUtils.mkdir_p(Puppet[:statedir])
35
 
        Puppet[:ignoreschedules] = false
36
 
        # Okay, make our manifest
37
 
        file = tempfile()
38
 
        created = tempfile()
39
 
        # We specify the schedule here, because I was having problems with
40
 
        # using default schedules.
41
 
        @code = %{
42
 
                class yayness {
43
 
                    schedule { "yayness": period => weekly }
44
 
                    file { "#{created}": ensure => file, schedule => yayness }
45
 
                }
46
 
 
47
 
                include yayness
48
 
            }
49
 
 
50
 
        @client = mkclient(@code)
51
 
 
52
 
        @runner = Puppet::Network::Handler.runner.new
53
 
    end
54
 
 
55
 
    def test_runner_when_in_foreground
56
 
        @client.expects(:run).with(:tags => "mytags", :ignoreschedules => true)
57
 
 
58
 
        Process.expects(:newthread).never
59
 
 
60
 
        @runner.run("mytags", true, true)
61
 
    end
62
 
 
63
 
    def test_runner_when_in_background
64
 
        @client.expects(:run).with(:tags => "mytags", :ignoreschedules => true)
65
 
 
66
 
        Puppet.expects(:newthread).yields
67
 
 
68
 
        @runner.run("mytags", true, false)
 
9
    include PuppetTest
 
10
 
 
11
    def test_it_calls_agent_runner
 
12
        runner = mock 'runner'
 
13
        Puppet::Agent::Runner.expects(:new).with(:tags => "mytags", :ignoreschedules => true, :background => false).returns runner
 
14
        runner.expects(:run)
 
15
        runner.expects(:status).returns "yay"
 
16
 
 
17
 
 
18
        assert_equal("yay", Puppet::Network::Handler.runner.new.run("mytags", true, true))
69
19
    end
70
20
end