File: queue_spec.rb

package info (click to toggle)
puppet-module-puppetlabs-rabbitmq 8.5.0-10
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,192 kB
  • sloc: ruby: 5,227; sh: 10; makefile: 4
file content (246 lines) | stat: -rw-r--r-- 6,884 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
require 'spec_helper_acceptance'

describe 'rabbitmq binding:' do
  context 'create binding and queue resources when using default management port' do
    it 'runs successfully' do
      pp = <<-EOS
      if $facts['os']['family'] == 'RedHat' {
        class { 'erlang': epel_enable => true }
        Class['erlang'] -> Class['rabbitmq']
      }
      class { 'rabbitmq':
        service_manage    => true,
        port              => 5672,
        delete_guest_user => true,
        admin_enable      => true,
      } ->

      rabbitmq_user { 'dan':
        admin    => true,
        password => 'bar',
        tags     => ['monitoring', 'tag1'],
      } ->

      rabbitmq_user_permissions { 'dan@host1':
        configure_permission => '.*',
        read_permission      => '.*',
        write_permission     => '.*',
      }

      rabbitmq_vhost { 'host1':
        ensure => present,
      } ->

      rabbitmq_exchange { 'exchange1@host1':
        user     => 'dan',
        password => 'bar',
        type     => 'topic',
        ensure   => present,
      } ->

      rabbitmq_queue { 'queue1@host1':
        user        => 'dan',
        password    => 'bar',
        durable     => true,
        auto_delete => false,
        ensure      => present,
      } ->

      rabbitmq_binding { 'exchange1@queue1@host1':
        user             => 'dan',
        password         => 'bar',
        destination_type => 'queue',
        routing_key      => '#',
        ensure           => present,
      }

      EOS

      apply_manifest(pp, catch_failures: true)
      apply_manifest(pp, catch_changes: true)
    end

    # rubocop:disable RSpec/MultipleExpectations
    it 'has the binding' do
      shell('rabbitmqctl list_bindings -q -p host1') do |r|
        expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\s#})
        expect(r.exit_code).to be_zero
      end
    end

    it 'has the queue' do
      shell('rabbitmqctl list_queues -q -p host1') do |r|
        expect(r.stdout).to match(%r{queue1})
        expect(r.exit_code).to be_zero
      end
    end
    # rubocop:enable RSpec/MultipleExpectations
  end

  context 'create multiple bindings when same source / destination / vhost but different routing keys' do
    it 'runs successfully' do
      pp = <<-EOS
      if $facts['os']['family'] == 'RedHat' {
        class { 'erlang': epel_enable => true }
        Class['erlang'] -> Class['rabbitmq']
      }
      class { 'rabbitmq':
        service_manage    => true,
        port              => 5672,
        delete_guest_user => true,
        admin_enable      => true,
      } ->

      rabbitmq_user { 'dan':
        admin    => true,
        password => 'bar',
        tags     => ['monitoring', 'tag1'],
      } ->

      rabbitmq_user_permissions { 'dan@host1':
        configure_permission => '.*',
        read_permission      => '.*',
        write_permission     => '.*',
      }

      rabbitmq_vhost { 'host1':
        ensure => present,
      } ->

      rabbitmq_exchange { 'exchange1@host1':
        user     => 'dan',
        password => 'bar',
        type     => 'topic',
        ensure   => present,
      } ->

      rabbitmq_queue { 'queue1@host1':
        user        => 'dan',
        password    => 'bar',
        durable     => true,
        auto_delete => false,
        ensure      => present,
      } ->

      rabbitmq_binding { 'binding 1':
        source           => 'exchange1',
        destination      => 'queue1',
        user             => 'dan',
        vhost            => 'host1',
        password         => 'bar',
        destination_type => 'queue',
        routing_key      => 'test1',
        ensure           => present,
      } ->

      rabbitmq_binding { 'binding 2':
        source           => 'exchange1',
        destination      => 'queue1',
        user             => 'dan',
        vhost            => 'host1',
        password         => 'bar',
        destination_type => 'queue',
        routing_key      => 'test2',
        ensure           => present,
      }

      EOS

      apply_manifest(pp, catch_failures: true)
      apply_manifest(pp, catch_changes: true)
    end

    # rubocop:disable RSpec/MultipleExpectations
    it 'has the bindings' do
      shell('rabbitmqctl list_bindings -q -p host1') do |r|
        expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\stest1})
        expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\stest2})
        expect(r.exit_code).to be_zero
      end
    end
    # rubocop:enable RSpec/MultipleExpectations

    it 'puppet resource shows a binding' do
      shell('puppet resource rabbitmq_binding') do |r|
        expect(r.stdout).to match(%r{source\s+=>\s+'exchange1',})
      end
    end
  end

  context 'create binding and queue resources when using a non-default management port' do
    it 'runs successfully' do
      pp = <<-EOS
      if $facts['os']['family'] == 'RedHat' {
        class { 'erlang': epel_enable => true }
        Class['erlang'] -> Class['rabbitmq']
      }
      class { 'rabbitmq':
        service_manage    => true,
        port              => 5672,
        management_port   => 11111,
        delete_guest_user => true,
        admin_enable      => true,
      } ->

      rabbitmq_user { 'dan':
        admin    => true,
        password => 'bar',
        tags     => ['monitoring', 'tag1'],
      } ->

      rabbitmq_user_permissions { 'dan@host2':
        configure_permission => '.*',
        read_permission      => '.*',
        write_permission     => '.*',
      }

      rabbitmq_vhost { 'host2':
        ensure => present,
      } ->

      rabbitmq_exchange { 'exchange2@host2':
        user     => 'dan',
        password => 'bar',
        type     => 'topic',
        ensure   => present,
      } ->

      rabbitmq_queue { 'queue2@host2':
        user        => 'dan',
        password    => 'bar',
        durable     => true,
        auto_delete => false,
        ensure      => present,
      } ->

      rabbitmq_binding { 'exchange2@queue2@host2':
        user             => 'dan',
        password         => 'bar',
        destination_type => 'queue',
        routing_key      => '#',
        ensure           => present,
      }

      EOS

      apply_manifest(pp, catch_failures: true)
      apply_manifest(pp, catch_changes: true)
    end

    # rubocop:disable RSpec/MultipleExpectations
    it 'has the binding' do
      shell('rabbitmqctl list_bindings -q -p host2') do |r|
        expect(r.stdout).to match(%r{exchange2\sexchange\squeue2\squeue\s#})
        expect(r.exit_code).to be_zero
      end
    end

    it 'has the queue' do
      shell('rabbitmqctl list_queues -q -p host2') do |r|
        expect(r.stdout).to match(%r{queue2})
        expect(r.exit_code).to be_zero
      end
    end
    # rubocop:enable RSpec/MultipleExpectations
  end
end