3 provider_class = Puppet::Type.type(:rabbitmq_binding).provider(:rabbitmqadmin)
4 describe provider_class do
6 Puppet::Type::Rabbitmq_binding.new(
7 name: 'source@target@/',
8 destination_type: :queue,
9 routing_key: 'blablub',
13 let(:provider) { provider_class.new(resource) }
15 # rubocop:disable RSpec/MultipleExpectations
16 describe '#instances' do
17 it 'returns instances' do
18 provider_class.expects(:rabbitmqctl).with('list_vhosts', '-q').returns <<-EOT
21 provider_class.expects(:rabbitmqctl).with(
22 'list_bindings', '-q', '-p', '/', 'source_name', 'destination_name', 'destination_kind', 'routing_key', 'arguments'
24 exchange\tdst_queue\tqueue\t*\t[]
26 instances = provider_class.instances
27 expect(instances.size).to eq(1)
28 expect(instances.map do |prov|
30 source: prov.get(:source),
31 destination: prov.get(:destination),
32 vhost: prov.get(:vhost),
33 routing_key: prov.get(:routing_key)
38 destination: 'dst_queue',
44 # rubocop:enable RSpec/MultipleExpectations
46 # rubocop:disable RSpec/MultipleExpectations
47 it 'returns multiple instances' do
48 provider_class.expects(:rabbitmqctl).with('list_vhosts', '-q').returns <<-EOT
51 provider_class.expects(:rabbitmqctl).with(
52 'list_bindings', '-q', '-p', '/', 'source_name', 'destination_name', 'destination_kind', 'routing_key', 'arguments'
54 exchange\tdst_queue\tqueue\trouting_one\t[]
55 exchange\tdst_queue\tqueue\trouting_two\t[]
57 instances = provider_class.instances
58 expect(instances.size).to eq(2)
59 expect(instances.map do |prov|
61 source: prov.get(:source),
62 destination: prov.get(:destination),
63 vhost: prov.get(:vhost),
64 routing_key: prov.get(:routing_key)
69 destination: 'dst_queue',
71 routing_key: 'routing_one'
75 destination: 'dst_queue',
77 routing_key: 'routing_two'
82 # rubocop:enable RSpec/MultipleExpectations
84 describe 'Test for prefetch error' do
86 Puppet::Type::Rabbitmq_binding.new(
89 destination: 'destqueue',
90 destination_type: :queue,
91 routing_key: 'blablubd',
97 provider_class.expects(:rabbitmqctl).with('list_vhosts', '-q').returns <<-EOT
100 provider_class.expects(:rabbitmqctl).with(
101 'list_bindings', '-q', '-p', '/', 'source_name', 'destination_name', 'destination_kind', 'routing_key', 'arguments'
103 exchange\tdst_queue\tqueue\t*\t[]
106 provider_class.prefetch({})
110 # Test resource to match against
111 provider_class.expects(:rabbitmqctl).with('list_vhosts', '-q').returns <<-EOT
114 provider_class.expects(:rabbitmqctl).with(
115 'list_bindings', '-q', '-p', '/', 'source_name', 'destination_name', 'destination_kind', 'routing_key', 'arguments'
117 exchange\tdst_queue\tqueue\t*\t[]
120 provider_class.prefetch('binding1' => resource)
124 describe '#create' do
125 it 'calls rabbitmqadmin to create' do
126 provider.expects(:rabbitmqadmin).with(
127 'declare', 'binding', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf',
128 'source=source', 'destination=target', 'arguments={}', 'routing_key=blablub', 'destination_type=queue'
133 context 'specifying credentials' do
135 Puppet::Type::Rabbitmq_binding.new(
136 name: 'source@test2@/',
137 destination_type: :queue,
138 routing_key: 'blablubd',
144 let(:provider) { provider_class.new(resource) }
146 it 'calls rabbitmqadmin to create' do
147 provider.expects(:rabbitmqadmin).with(
148 'declare', 'binding', '--vhost=/', '--user=colin', '--password=secret', '-c', '/etc/rabbitmq/rabbitmqadmin.conf',
149 'source=source', 'destination=test2', 'arguments={}', 'routing_key=blablubd', 'destination_type=queue'
155 context 'new queue_bindings' do
157 Puppet::Type::Rabbitmq_binding.new(
160 destination: 'destqueue',
161 destination_type: :queue,
162 routing_key: 'blablubd',
166 let(:provider) { provider_class.new(resource) }
168 it 'calls rabbitmqadmin to create' do
169 provider.expects(:rabbitmqadmin).with(
170 'declare', 'binding', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf',
171 'source=exchange1', 'destination=destqueue', 'arguments={}', 'routing_key=blablubd', 'destination_type=queue'
178 describe '#destroy' do
179 it 'calls rabbitmqadmin to destroy' do
180 provider.expects(:rabbitmqadmin).with(
181 'delete', 'binding', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf',
182 'source=source', 'destination_type=queue', 'destination=target', 'properties_key=blablub'