]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/rabbitmq/spec/unit/puppet/type/rabbitmq_policy_spec.rb
move to puppetlabs rabbitmq module
[dsa-puppet.git] / 3rdparty / modules / rabbitmq / spec / unit / puppet / type / rabbitmq_policy_spec.rb
1 require 'puppet'
2 require 'puppet/type/rabbitmq_policy'
3
4 describe Puppet::Type.type(:rabbitmq_policy) do
5
6   before do
7     @policy = Puppet::Type.type(:rabbitmq_policy).new(
8       :name       => 'ha-all@/',
9       :pattern    => '.*',
10       :definition => {
11         'ha-mode' => 'all'
12       })
13   end
14
15   it 'should accept a valid name' do
16     @policy[:name] = 'ha-all@/'
17     @policy[:name].should == 'ha-all@/'
18   end
19
20   it 'should require a name' do
21     expect {
22       Puppet::Type.type(:rabbitmq_policy).new({})
23     }.to raise_error(Puppet::Error, 'Title or name must be provided')
24   end
25
26   it 'should fail when name does not have a @' do
27     expect {
28       @policy[:name] = 'ha-all'
29     }.to raise_error(Puppet::Error, /Valid values match/)
30   end
31
32   it 'should accept a valid regex for pattern' do
33     @policy[:pattern] = '.*?'
34     @policy[:pattern].should == '.*?'
35   end
36
37   it 'should accept an empty string for pattern' do
38     @policy[:pattern] = ''
39     @policy[:pattern].should == ''
40   end
41
42   it 'should not accept invalid regex for pattern' do
43     expect {
44       @policy[:pattern] = '*'
45     }.to raise_error(Puppet::Error, /Invalid regexp/)
46   end
47
48   it 'should accept valid value for applyto' do
49     [:all, :exchanges, :queues].each do |v|
50       @policy[:applyto] = v
51       @policy[:applyto].should == v
52     end
53   end
54
55   it 'should not accept invalid value for applyto' do
56     expect {
57       @policy[:applyto] = 'me'
58     }.to raise_error(Puppet::Error, /Invalid value/)
59   end
60
61   it 'should accept a valid hash for definition' do
62     definition = {'ha-mode' => 'all', 'ha-sync-mode' => 'automatic'}
63     @policy[:definition] = definition
64     @policy[:definition].should == definition
65   end
66
67   it 'should not accept invalid hash for definition' do
68     expect {
69       @policy[:definition] = 'ha-mode'
70     }.to raise_error(Puppet::Error, /Invalid definition/)
71
72     expect {
73       @policy[:definition] = {'ha-mode' => ['a', 'b']}
74     }.to raise_error(Puppet::Error, /Invalid definition/)
75   end
76
77   it 'should accept valid value for priority' do
78     [0, 10, '0', '10'].each do |v|
79       @policy[:priority] = v
80       @policy[:priority].should == v
81     end
82   end
83
84   it 'should not accept invalid value for priority' do
85     ['-1', -1, '1.0', 1.0, 'abc', ''].each do |v|
86       expect {
87         @policy[:priority] = v
88       }.to raise_error(Puppet::Error, /Invalid value/)
89     end
90   end
91
92   it 'should accept and convert ha-params for ha-mode exactly' do
93     definition = {'ha-mode' => 'exactly', 'ha-params' => '2'}
94     @policy[:definition] = definition
95     @policy[:definition]['ha-params'].should be_a(Fixnum)
96     @policy[:definition]['ha-params'].should == 2
97   end
98
99   it 'should not accept non-numeric ha-params for ha-mode exactly' do
100     definition = {'ha-mode' => 'exactly', 'ha-params' => 'nonnumeric'}
101     expect {
102       @policy[:definition] = definition
103     }.to raise_error(Puppet::Error, /Invalid ha-params.*nonnumeric.*exactly/)
104   end
105
106   it 'should accept and convert the expires value' do
107     definition = {'expires' => '1800000'}
108     @policy[:definition] = definition
109     @policy[:definition]['expires'].should be_a(Fixnum)
110     @policy[:definition]['expires'].should == 1800000
111   end
112
113   it 'should not accept non-numeric expires value' do
114     definition = {'expires' => 'future'}
115     expect {
116       @policy[:definition] = definition
117     }.to raise_error(Puppet::Error, /Invalid expires value.*future/)
118   end
119 end