2 describe Puppet::Type.type(:rabbitmq_policy) do
4 Puppet::Type.type(:rabbitmq_policy).new(
13 it 'accepts a valid name' do
14 policy[:name] = 'ha-all@/'
15 expect(policy[:name]).to eq('ha-all@/')
18 it 'requires a name' do
20 Puppet::Type.type(:rabbitmq_policy).new({})
21 end.to raise_error(Puppet::Error, 'Title or name must be provided')
24 it 'fails when name does not have a @' do
26 policy[:name] = 'ha-all'
27 end.to raise_error(Puppet::Error, %r{Valid values match})
30 it 'accepts a valid regex for pattern' do
31 policy[:pattern] = '.*?'
32 expect(policy[:pattern]).to eq('.*?')
35 it 'accepts an empty string for pattern' do
37 expect(policy[:pattern]).to eq('')
40 it 'does not accept invalid regex for pattern' do
42 policy[:pattern] = '*'
43 end.to raise_error(Puppet::Error, %r{Invalid regexp})
46 it 'accepts valid value for applyto' do
47 [:all, :exchanges, :queues].each do |v|
49 expect(policy[:applyto]).to eq(v)
53 it 'does not accept invalid value for applyto' do
55 policy[:applyto] = 'me'
56 end.to raise_error(Puppet::Error, %r{Invalid value})
59 it 'accepts a valid hash for definition' do
60 definition = { 'ha-mode' => 'all', 'ha-sync-mode' => 'automatic' }
61 policy[:definition] = definition
62 expect(policy[:definition]).to eq(definition)
65 it 'does not accept a string for definition' do
67 policy[:definition] = 'ha-mode'
68 end.to raise_error(Puppet::Error, %r{Invalid definition})
71 it 'does not accept invalid hash for definition' do
73 policy[:definition] = { 'ha-mode' => %w[a b] }
74 end.to raise_error(Puppet::Error, %r{Invalid definition})
77 it 'accepts valid value for priority' do
78 [0, 10, '0', '10'].each do |v|
80 expect(policy[:priority]).to eq(v)
84 it 'does not accept invalid value for priority' do
85 ['-1', -1, '1.0', 1.0, 'abc', ''].each do |v|
88 end.to raise_error(Puppet::Error, %r{Invalid value})
92 it 'accepts and convert ha-params for ha-mode exactly' do
93 definition = { 'ha-mode' => 'exactly', 'ha-params' => '2' }
94 policy[:definition] = definition
95 expect(policy[:definition]['ha-params']).to eq(2)
98 it 'does not accept non-numeric ha-params for ha-mode exactly' do
99 definition = { 'ha-mode' => 'exactly', 'ha-params' => 'nonnumeric' }
101 policy[:definition] = definition
102 end.to raise_error(Puppet::Error, %r{Invalid ha-params.*nonnumeric.*exactly})
105 it 'accepts and convert the expires value' do
106 definition = { 'expires' => '1800000' }
107 policy[:definition] = definition
108 expect(policy[:definition]['expires']).to eq(1_800_000)
111 it 'does not accept non-numeric expires value' do
112 definition = { 'expires' => 'future' }
114 policy[:definition] = definition
115 end.to raise_error(Puppet::Error, %r{Invalid expires value.*future})
118 it 'accepts and convert the message-ttl value' do
119 definition = { 'message-ttl' => '1800000' }
120 policy[:definition] = definition
121 expect(policy[:definition]['message-ttl']).to eq(1_800_000)
124 it 'does not accept non-numeric message-ttl value' do
125 definition = { 'message-ttl' => 'future' }
127 policy[:definition] = definition
128 end.to raise_error(Puppet::Error, %r{Invalid message-ttl value.*future})
131 it 'accepts and convert the max-length value' do
132 definition = { 'max-length' => '1800000' }
133 policy[:definition] = definition
134 expect(policy[:definition]['max-length']).to eq(1_800_000)
137 it 'does not accept non-numeric max-length value' do
138 definition = { 'max-length' => 'future' }
140 policy[:definition] = definition
141 end.to raise_error(Puppet::Error, %r{Invalid max-length value.*future})
144 it 'accepts and convert the max-length-bytes value' do
145 definition = { 'max-length-bytes' => '1800000' }
146 policy[:definition] = definition
147 expect(policy[:definition]['max-length-bytes']).to eq(1_800_000)
150 it 'does not accept non-numeric max-length-bytes value' do
151 definition = { 'max-length-bytes' => 'future' }
153 policy[:definition] = definition
154 end.to raise_error(Puppet::Error, %r{Invalid max-length-bytes value.*future})
157 it 'accepts and convert the shards-per-node value' do
158 definition = { 'shards-per-node' => '1800000' }
159 policy[:definition] = definition
160 expect(policy[:definition]['shards-per-node']).to eq(1_800_000)
163 it 'does not accept non-numeric shards-per-node value' do
164 definition = { 'shards-per-node' => 'future' }
166 policy[:definition] = definition
167 end.to raise_error(Puppet::Error, %r{Invalid shards-per-node value.*future})
170 it 'accepts and convert the ha-sync-batch-size value' do
171 definition = { 'ha-sync-batch-size' => '1800000' }
172 policy[:definition] = definition
173 expect(policy[:definition]['ha-sync-batch-size']).to eq(1_800_000)
176 it 'does not accept non-numeric ha-sync-batch-size value' do
177 definition = { 'ha-sync-batch-size' => 'future' }
179 policy[:definition] = definition
180 end.to raise_error(Puppet::Error, %r{Invalid ha-sync-batch-size value.*future})
183 context 'accepts list value in ha-params when ha-mode = nodes' do
185 policy[:definition] = definition
188 let(:definition) { { 'ha-mode' => 'nodes', 'ha-params' => ['rabbit@rabbit-01', 'rabbit@rabbit-02'] } }
190 it { expect(policy[:definition]['ha-mode']).to eq('nodes') }
191 it { expect(policy[:definition]['ha-params']).to be_a(Array) }
192 it { expect(policy[:definition]['ha-params'][0]).to eq('rabbit@rabbit-01') }
193 it { expect(policy[:definition]['ha-params'][1]).to eq('rabbit@rabbit-02') }
196 it 'does not accept non-list value in ha-params when ha-mode = nodes' do
197 definition = { 'ha-mode' => 'nodes', 'ha-params' => 'this-will-fail' }
199 policy[:definition] = definition
200 end.to raise_error(Puppet::Error, %r{Invalid definition, value this-will-fail for key ha-params is not an array})