|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper_acceptance' |
| 4 | + |
| 5 | +describe 'rabbitmq_binding:' do |
| 6 | + before do |
| 7 | + pp = <<-EOS |
| 8 | + class { 'rabbitmq': |
| 9 | + service_manage => true, |
| 10 | + port => 5672, |
| 11 | + delete_guest_user => true, |
| 12 | + admin_enable => true, |
| 13 | + } |
| 14 | + -> rabbitmq_user { 'dan': |
| 15 | + admin => true, |
| 16 | + password => 'bar', |
| 17 | + tags => ['monitoring', 'tag1'], |
| 18 | + } |
| 19 | + -> rabbitmq_user_permissions { 'dan@host1': |
| 20 | + configure_permission => '.*', |
| 21 | + read_permission => '.*', |
| 22 | + write_permission => '.*', |
| 23 | + } |
| 24 | + rabbitmq_vhost { 'host1': |
| 25 | + ensure => present, |
| 26 | + } |
| 27 | + -> rabbitmq_exchange { 'exchange1@host1': |
| 28 | + user => 'dan', |
| 29 | + password => 'bar', |
| 30 | + type => 'topic', |
| 31 | + ensure => present, |
| 32 | + } |
| 33 | + -> rabbitmq_queue { 'queue1@host1': |
| 34 | + user => 'dan', |
| 35 | + password => 'bar', |
| 36 | + durable => true, |
| 37 | + auto_delete => false, |
| 38 | + ensure => present, |
| 39 | + } |
| 40 | + EOS |
| 41 | + |
| 42 | + apply_manifest(pp, catch_failures: true) |
| 43 | + end |
| 44 | + |
| 45 | + context 'when using one routing_key' do |
| 46 | + it_behaves_like 'an idempotent resource' do |
| 47 | + let(:manifest) do |
| 48 | + <<-PUPPET |
| 49 | + rabbitmq_binding { 'exchange1@queue1@host1': |
| 50 | + user => 'dan', |
| 51 | + password => 'bar', |
| 52 | + destination_type => 'queue', |
| 53 | + routing_key => '#', |
| 54 | + ensure => present, |
| 55 | + } |
| 56 | + PUPPET |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + it 'binding exist' do |
| 61 | + shell('rabbitmqctl list_bindings -q -p host1') do |r| |
| 62 | + expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\s#}) |
| 63 | + expect(r.exit_code).to be_zero |
| 64 | + end |
| 65 | + end |
| 66 | + |
| 67 | + it 'resource has the queue' do |
| 68 | + shell('rabbitmqctl list_queues -q -p host1') do |r| |
| 69 | + expect(r.stdout).to match(%r{queue1}) |
| 70 | + expect(r.exit_code).to be_zero |
| 71 | + end |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + context 'when using two routing_keys' do |
| 76 | + it_behaves_like 'an idempotent resource' do |
| 77 | + let(:manifest) do |
| 78 | + <<-PUPPET |
| 79 | + rabbitmq_binding { 'binding 1': |
| 80 | + source => 'exchange1', |
| 81 | + destination => 'queue1', |
| 82 | + user => 'dan', |
| 83 | + vhost => 'host1', |
| 84 | + password => 'bar', |
| 85 | + destination_type => 'queue', |
| 86 | + routing_key => 'test1', |
| 87 | + ensure => present, |
| 88 | + } |
| 89 | + -> rabbitmq_binding { 'binding 2': |
| 90 | + source => 'exchange1', |
| 91 | + destination => 'queue1', |
| 92 | + user => 'dan', |
| 93 | + vhost => 'host1', |
| 94 | + password => 'bar', |
| 95 | + destination_type => 'queue', |
| 96 | + routing_key => 'test2', |
| 97 | + ensure => present, |
| 98 | + } |
| 99 | + PUPPET |
| 100 | + end |
| 101 | + end |
| 102 | + |
| 103 | + it 'resource has the bindings' do |
| 104 | + shell('rabbitmqctl list_bindings -q -p host1') do |r| |
| 105 | + expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\stest1}) |
| 106 | + expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\stest2}) |
| 107 | + expect(r.exit_code).to be_zero |
| 108 | + end |
| 109 | + end |
| 110 | + |
| 111 | + it 'puppet resource shows a binding' do |
| 112 | + shell('puppet resource rabbitmq_binding') do |r| |
| 113 | + expect(r.stdout).to match(%r{source\s+=>\s+'exchange1',}) |
| 114 | + end |
| 115 | + end |
| 116 | + end |
| 117 | +end |
0 commit comments