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

« back to all changes in this revision

Viewing changes to spec/unit/util/queue.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:
 
1
#!/usr/bin/env ruby
 
2
 
 
3
require File.dirname(__FILE__) + '/../../spec_helper'
 
4
require 'puppet/util/queue'
 
5
require 'spec/mocks'
 
6
 
 
7
def make_test_client_class(n)
 
8
    c = Class.new do
 
9
        class <<self
 
10
            attr_accessor :name
 
11
            def to_s
 
12
                name
 
13
            end
 
14
        end
 
15
    end
 
16
    c.name = n
 
17
    c
 
18
end
 
19
 
 
20
mod = Puppet::Util::Queue
 
21
client_classes = { :default => make_test_client_class('Bogus::Default'), :setup => make_test_client_class('Bogus::Setup') }
 
22
mod.register_queue_type(client_classes[:default], :default)
 
23
mod.register_queue_type(client_classes[:setup], :setup)
 
24
 
 
25
describe Puppet::Util::Queue do
 
26
    before :each do
 
27
        @class = Class.new do
 
28
            extend mod
 
29
        end
 
30
    end
 
31
 
 
32
    context 'when determining a type name from a class' do
 
33
        it 'should handle a simple one-word class name' do
 
34
            mod.queue_type_from_class(make_test_client_class('Foo')).should == :foo
 
35
        end
 
36
 
 
37
        it 'should handle a simple two-word class name' do
 
38
            mod.queue_type_from_class(make_test_client_class('FooBar')).should == :foo_bar
 
39
        end
 
40
 
 
41
        it 'should handle a two-part class name with one terminating word' do
 
42
            mod.queue_type_from_class(make_test_client_class('Foo::Bar')).should == :bar
 
43
        end
 
44
 
 
45
        it 'should handle a two-part class name with two terminating words' do
 
46
            mod.queue_type_from_class(make_test_client_class('Foo::BarBah')).should == :bar_bah
 
47
        end
 
48
    end
 
49
 
 
50
    context 'when registering a queue client class' do
 
51
        c = make_test_client_class('Foo::Bogus')
 
52
        it 'uses the proper default name logic when type is unspecified' do
 
53
            mod.register_queue_type(c)
 
54
            mod.queue_type_to_class(:bogus).should == c
 
55
        end
 
56
 
 
57
        it 'uses an explicit type name when provided' do
 
58
            mod.register_queue_type(c, :aardvark)
 
59
            mod.queue_type_to_class(:aardvark).should == c
 
60
        end
 
61
 
 
62
        it 'throws an exception when type names conflict' do
 
63
            mod.register_queue_type( make_test_client_class('Conflict') )
 
64
            lambda { mod.register_queue_type( c, :conflict) }.should raise_error
 
65
        end
 
66
 
 
67
        it 'handle multiple, non-conflicting registrations' do
 
68
            a = make_test_client_class('TestA')
 
69
            b = make_test_client_class('TestB')
 
70
            mod.register_queue_type(a)
 
71
            mod.register_queue_type(b)
 
72
            mod.queue_type_to_class(:test_a).should == a
 
73
            mod.queue_type_to_class(:test_b).should == b
 
74
        end
 
75
 
 
76
        it 'throws an exception when type name is unknown' do
 
77
            lambda { mod.queue_type_to_class(:nope) }.should raise_error
 
78
        end
 
79
    end
 
80
 
 
81
    context 'when determining client type' do
 
82
        it 'returns client class based on the :queue_type setting' do
 
83
            Puppet.settings.expects(:value).with(:queue_type).returns(:myqueue)
 
84
            Puppet::Util::Queue.expects(:queue_type_to_class).with(:myqueue).returns "eh"
 
85
            @class.client_class.should == "eh"
 
86
        end
 
87
    end
 
88
end