Update 3rdparty rabbitmq module
[mirror/dsa-puppet.git] / 3rdparty / modules / rabbitmq / spec / acceptance / queue_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'rabbitmq binding:' do
4   context 'create binding and queue resources when using default management port' do
5     it 'runs successfully' do
6       pp = <<-EOS
7       if $facts['os']['family'] == 'RedHat' {
8         class { 'erlang': epel_enable => true }
9         Class['erlang'] -> Class['rabbitmq']
10       }
11       class { 'rabbitmq':
12         service_manage    => true,
13         port              => 5672,
14         delete_guest_user => true,
15         admin_enable      => true,
16       } ->
17
18       rabbitmq_user { 'dan':
19         admin    => true,
20         password => 'bar',
21         tags     => ['monitoring', 'tag1'],
22       } ->
23
24       rabbitmq_user_permissions { 'dan@host1':
25         configure_permission => '.*',
26         read_permission      => '.*',
27         write_permission     => '.*',
28       }
29
30       rabbitmq_vhost { 'host1':
31         ensure => present,
32       } ->
33
34       rabbitmq_exchange { 'exchange1@host1':
35         user     => 'dan',
36         password => 'bar',
37         type     => 'topic',
38         ensure   => present,
39       } ->
40
41       rabbitmq_queue { 'queue1@host1':
42         user        => 'dan',
43         password    => 'bar',
44         durable     => true,
45         auto_delete => false,
46         ensure      => present,
47       } ->
48
49       rabbitmq_binding { 'exchange1@queue1@host1':
50         user             => 'dan',
51         password         => 'bar',
52         destination_type => 'queue',
53         routing_key      => '#',
54         ensure           => present,
55       }
56
57       EOS
58
59       apply_manifest(pp, catch_failures: true)
60       apply_manifest(pp, catch_changes: true)
61     end
62
63     # rubocop:disable RSpec/MultipleExpectations
64     it 'has the binding' do
65       shell('rabbitmqctl list_bindings -q -p host1') do |r|
66         expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\s#})
67         expect(r.exit_code).to be_zero
68       end
69     end
70
71     it 'has the queue' do
72       shell('rabbitmqctl list_queues -q -p host1') do |r|
73         expect(r.stdout).to match(%r{queue1})
74         expect(r.exit_code).to be_zero
75       end
76     end
77     # rubocop:enable RSpec/MultipleExpectations
78   end
79
80   context 'create multiple bindings when same source / destination / vhost but different routing keys' do
81     it 'runs successfully' do
82       pp = <<-EOS
83       if $facts['os']['family'] == 'RedHat' {
84         class { 'erlang': epel_enable => true }
85         Class['erlang'] -> Class['rabbitmq']
86       }
87       class { 'rabbitmq':
88         service_manage    => true,
89         port              => 5672,
90         delete_guest_user => true,
91         admin_enable      => true,
92       } ->
93
94       rabbitmq_user { 'dan':
95         admin    => true,
96         password => 'bar',
97         tags     => ['monitoring', 'tag1'],
98       } ->
99
100       rabbitmq_user_permissions { 'dan@host1':
101         configure_permission => '.*',
102         read_permission      => '.*',
103         write_permission     => '.*',
104       }
105
106       rabbitmq_vhost { 'host1':
107         ensure => present,
108       } ->
109
110       rabbitmq_exchange { 'exchange1@host1':
111         user     => 'dan',
112         password => 'bar',
113         type     => 'topic',
114         ensure   => present,
115       } ->
116
117       rabbitmq_queue { 'queue1@host1':
118         user        => 'dan',
119         password    => 'bar',
120         durable     => true,
121         auto_delete => false,
122         ensure      => present,
123       } ->
124
125       rabbitmq_binding { 'binding 1':
126         source           => 'exchange1',
127         destination      => 'queue1',
128         user             => 'dan',
129         vhost            => 'host1',
130         password         => 'bar',
131         destination_type => 'queue',
132         routing_key      => 'test1',
133         ensure           => present,
134       } ->
135
136       rabbitmq_binding { 'binding 2':
137         source           => 'exchange1',
138         destination      => 'queue1',
139         user             => 'dan',
140         vhost            => 'host1',
141         password         => 'bar',
142         destination_type => 'queue',
143         routing_key      => 'test2',
144         ensure           => present,
145       }
146
147       EOS
148
149       apply_manifest(pp, catch_failures: true)
150       apply_manifest(pp, catch_changes: true)
151     end
152
153     # rubocop:disable RSpec/MultipleExpectations
154     it 'has the bindings' do
155       shell('rabbitmqctl list_bindings -q -p host1') do |r|
156         expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\stest1})
157         expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\stest2})
158         expect(r.exit_code).to be_zero
159       end
160     end
161     # rubocop:enable RSpec/MultipleExpectations
162
163     it 'puppet resource shows a binding' do
164       shell('puppet resource rabbitmq_binding') do |r|
165         expect(r.stdout).to match(%r{source\s+=>\s+'exchange1',})
166       end
167     end
168   end
169
170   context 'create binding and queue resources when using a non-default management port' do
171     it 'runs successfully' do
172       pp = <<-EOS
173       if $facts['os']['family'] == 'RedHat' {
174         class { 'erlang': epel_enable => true }
175         Class['erlang'] -> Class['rabbitmq']
176       }
177       class { 'rabbitmq':
178         service_manage    => true,
179         port              => 5672,
180         management_port   => 11111,
181         delete_guest_user => true,
182         admin_enable      => true,
183       } ->
184
185       rabbitmq_user { 'dan':
186         admin    => true,
187         password => 'bar',
188         tags     => ['monitoring', 'tag1'],
189       } ->
190
191       rabbitmq_user_permissions { 'dan@host2':
192         configure_permission => '.*',
193         read_permission      => '.*',
194         write_permission     => '.*',
195       }
196
197       rabbitmq_vhost { 'host2':
198         ensure => present,
199       } ->
200
201       rabbitmq_exchange { 'exchange2@host2':
202         user     => 'dan',
203         password => 'bar',
204         type     => 'topic',
205         ensure   => present,
206       } ->
207
208       rabbitmq_queue { 'queue2@host2':
209         user        => 'dan',
210         password    => 'bar',
211         durable     => true,
212         auto_delete => false,
213         ensure      => present,
214       } ->
215
216       rabbitmq_binding { 'exchange2@queue2@host2':
217         user             => 'dan',
218         password         => 'bar',
219         destination_type => 'queue',
220         routing_key      => '#',
221         ensure           => present,
222       }
223
224       EOS
225
226       apply_manifest(pp, catch_failures: true)
227       apply_manifest(pp, catch_changes: true)
228     end
229
230     # rubocop:disable RSpec/MultipleExpectations
231     it 'has the binding' do
232       shell('rabbitmqctl list_bindings -q -p host2') do |r|
233         expect(r.stdout).to match(%r{exchange2\sexchange\squeue2\squeue\s#})
234         expect(r.exit_code).to be_zero
235       end
236     end
237
238     it 'has the queue' do
239       shell('rabbitmqctl list_queues -q -p host2') do |r|
240         expect(r.stdout).to match(%r{queue2})
241         expect(r.exit_code).to be_zero
242       end
243     end
244     # rubocop:enable RSpec/MultipleExpectations
245   end
246 end