2 require 'puppet/type/rabbitmq_policy'
4 describe Puppet::Type.type(:rabbitmq_policy) do
7 @policy = Puppet::Type.type(:rabbitmq_policy).new(
15 it 'should accept a valid name' do
16 @policy[:name] = 'ha-all@/'
17 @policy[:name].should == 'ha-all@/'
20 it 'should require a name' do
22 Puppet::Type.type(:rabbitmq_policy).new({})
23 }.to raise_error(Puppet::Error, 'Title or name must be provided')
26 it 'should fail when name does not have a @' do
28 @policy[:name] = 'ha-all'
29 }.to raise_error(Puppet::Error, /Valid values match/)
32 it 'should accept a valid regex for pattern' do
33 @policy[:pattern] = '.*?'
34 @policy[:pattern].should == '.*?'
37 it 'should accept an empty string for pattern' do
38 @policy[:pattern] = ''
39 @policy[:pattern].should == ''
42 it 'should not accept invalid regex for pattern' do
44 @policy[:pattern] = '*'
45 }.to raise_error(Puppet::Error, /Invalid regexp/)
48 it 'should accept valid value for applyto' do
49 [:all, :exchanges, :queues].each do |v|
51 @policy[:applyto].should == v
55 it 'should not accept invalid value for applyto' do
57 @policy[:applyto] = 'me'
58 }.to raise_error(Puppet::Error, /Invalid value/)
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
67 it 'should not accept invalid hash for definition' do
69 @policy[:definition] = 'ha-mode'
70 }.to raise_error(Puppet::Error, /Invalid definition/)
73 @policy[:definition] = {'ha-mode' => ['a', 'b']}
74 }.to raise_error(Puppet::Error, /Invalid definition/)
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
84 it 'should not accept invalid value for priority' do
85 ['-1', -1, '1.0', 1.0, 'abc', ''].each do |v|
87 @policy[:priority] = v
88 }.to raise_error(Puppet::Error, /Invalid value/)
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
99 it 'should not accept non-numeric ha-params for ha-mode exactly' do
100 definition = {'ha-mode' => 'exactly', 'ha-params' => 'nonnumeric'}
102 @policy[:definition] = definition
103 }.to raise_error(Puppet::Error, /Invalid ha-params.*nonnumeric.*exactly/)
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
113 it 'should not accept non-numeric expires value' do
114 definition = {'expires' => 'future'}
116 @policy[:definition] = definition
117 }.to raise_error(Puppet::Error, /Invalid expires value.*future/)