91161a40edd28a22ca06221becfd0fb9fe36c7fc
[mirror/dsa-puppet.git] / 3rdparty / modules / rabbitmq / spec / acceptance / policy_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'rabbitmq policy on a vhost:' do
4   context 'create policy resource' 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_vhost { 'myhost':
19         ensure => present,
20       } ->
21
22       rabbitmq_policy { 'ha-all@myhost':
23         pattern    => '.*',
24         priority   => 0,
25         applyto    => 'all',
26         definition => {
27           'ha-mode'      => 'all',
28           'ha-sync-mode' => 'automatic',
29         },
30       }
31
32       rabbitmq_policy { 'eu-federation@myhost':
33         pattern    => '^eu\\.',
34         priority   => 0,
35         applyto    => 'all',
36         definition => {
37           'federation-upstream-set' => 'all',
38         },
39       }
40       EOS
41
42       apply_manifest(pp, catch_failures: true)
43       apply_manifest(pp, catch_changes: true)
44
45       # Apply twice to ensure no changes the second time.
46       apply_manifest(pp, catch_failures: true)
47       expect(apply_manifest(pp, catch_changes: true).exit_code).to be_zero
48     end
49
50     # rubocop:disable RSpec/MultipleExpectations
51     it 'has the policy' do
52       shell('rabbitmqctl list_policies -p myhost') do |r|
53         expect(r.stdout).to match(%r{myhost.*ha-all.*ha-sync-mode})
54         expect(r.stdout).to match(%r{myhost.*eu-federation})
55         expect(r.exit_code).to be_zero
56       end
57     end
58     # rubocop:enable RSpec/MultipleExpectations
59   end
60 end