X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Frabbitmq%2Fspec%2Funit%2Fpuppet%2Fprovider%2Frabbitmq_binding%2Frabbitmqadmin_spec.rb;h=e165d557c469cdb5b0b7df74bea222db0931ce66;hb=24caa46729f80fbba4be8b9b26ebcb3acc4cb0fb;hp=04015a33d3780ce5951a0109b04678b8d908967c;hpb=c7e7bcc28cc5dc48a7e284a3c82f33df27d1f57d;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/rabbitmq/spec/unit/puppet/provider/rabbitmq_binding/rabbitmqadmin_spec.rb b/3rdparty/modules/rabbitmq/spec/unit/puppet/provider/rabbitmq_binding/rabbitmqadmin_spec.rb index 04015a33d..e165d557c 100644 --- a/3rdparty/modules/rabbitmq/spec/unit/puppet/provider/rabbitmq_binding/rabbitmqadmin_spec.rb +++ b/3rdparty/modules/rabbitmq/spec/unit/puppet/provider/rabbitmq_binding/rabbitmqadmin_spec.rb @@ -1,187 +1,59 @@ -require 'spec_helper' - +require 'puppet' +require 'mocha/api' +RSpec.configure do |config| + config.mock_with :mocha +end provider_class = Puppet::Type.type(:rabbitmq_binding).provider(:rabbitmqadmin) describe provider_class do - let(:resource) do - Puppet::Type::Rabbitmq_binding.new( - name: 'source@target@/', - destination_type: :queue, - routing_key: 'blablub', - arguments: {} + before :each do + @resource = Puppet::Type::Rabbitmq_binding.new( + {:name => 'source@target@/', + :destination_type => :queue, + :routing_key => 'blablub', + :arguments => {} + } ) + @provider = provider_class.new(@resource) end - let(:provider) { provider_class.new(resource) } - # rubocop:disable RSpec/MultipleExpectations - describe '#instances' do - it 'returns instances' do - provider_class.expects(:rabbitmqctl).with('list_vhosts', '-q').returns <<-EOT + it 'should return instances' do + provider_class.expects(:rabbitmqctl).with('list_vhosts', '-q').returns <<-EOT / EOT - provider_class.expects(:rabbitmqctl).with( - 'list_bindings', '-q', '-p', '/', 'source_name', 'destination_name', 'destination_kind', 'routing_key', 'arguments' - ).returns <<-EOT -exchange\tdst_queue\tqueue\t*\t[] + provider_class.expects(:rabbitmqctl).with('list_bindings', '-q', '-p', '/', 'source_name', 'destination_name', 'destination_kind', 'routing_key', 'arguments').returns <<-EOT + queue queue queue [] EOT - instances = provider_class.instances - expect(instances.size).to eq(1) - expect(instances.map do |prov| - { - source: prov.get(:source), - destination: prov.get(:destination), - vhost: prov.get(:vhost), - routing_key: prov.get(:routing_key) - } - end).to eq([ - { - source: 'exchange', - destination: 'dst_queue', - vhost: '/', - routing_key: '*' - } - ]) - end - # rubocop:enable RSpec/MultipleExpectations - - # rubocop:disable RSpec/MultipleExpectations - it 'returns multiple instances' do - provider_class.expects(:rabbitmqctl).with('list_vhosts', '-q').returns <<-EOT -/ -EOT - provider_class.expects(:rabbitmqctl).with( - 'list_bindings', '-q', '-p', '/', 'source_name', 'destination_name', 'destination_kind', 'routing_key', 'arguments' - ).returns <<-EOT -exchange\tdst_queue\tqueue\trouting_one\t[] -exchange\tdst_queue\tqueue\trouting_two\t[] -EOT - instances = provider_class.instances - expect(instances.size).to eq(2) - expect(instances.map do |prov| - { - source: prov.get(:source), - destination: prov.get(:destination), - vhost: prov.get(:vhost), - routing_key: prov.get(:routing_key) - } - end).to eq([ - { - source: 'exchange', - destination: 'dst_queue', - vhost: '/', - routing_key: 'routing_one' - }, - { - source: 'exchange', - destination: 'dst_queue', - vhost: '/', - routing_key: 'routing_two' - } - ]) - end + instances = provider_class.instances + instances.size.should == 1 + end + + it 'should call rabbitmqadmin to create' do + @provider.expects(:rabbitmqadmin).with('declare', 'binding', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'source=source', 'destination=target', 'arguments={}', 'routing_key=blablub', 'destination_type=queue') + @provider.create end - # rubocop:enable RSpec/MultipleExpectations - - describe 'Test for prefetch error' do - let(:resource) do - Puppet::Type::Rabbitmq_binding.new( - name: 'binding1', - source: 'exchange1', - destination: 'destqueue', - destination_type: :queue, - routing_key: 'blablubd', - arguments: {} - ) - end - - it 'exists' do - provider_class.expects(:rabbitmqctl).with('list_vhosts', '-q').returns <<-EOT -/ -EOT - provider_class.expects(:rabbitmqctl).with( - 'list_bindings', '-q', '-p', '/', 'source_name', 'destination_name', 'destination_kind', 'routing_key', 'arguments' - ).returns <<-EOT -exchange\tdst_queue\tqueue\t*\t[] -EOT - - provider_class.prefetch({}) - end - - it 'matches' do - # Test resource to match against - provider_class.expects(:rabbitmqctl).with('list_vhosts', '-q').returns <<-EOT -/ -EOT - provider_class.expects(:rabbitmqctl).with( - 'list_bindings', '-q', '-p', '/', 'source_name', 'destination_name', 'destination_kind', 'routing_key', 'arguments' - ).returns <<-EOT -exchange\tdst_queue\tqueue\t*\t[] -EOT - provider_class.prefetch('binding1' => resource) - end + it 'should call rabbitmqadmin to destroy' do + @provider.expects(:rabbitmqadmin).with('delete', 'binding', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'source=source', 'destination_type=queue', 'destination=target', 'properties_key=blablub') + @provider.destroy end - describe '#create' do - it 'calls rabbitmqadmin to create' do - provider.expects(:rabbitmqadmin).with( - 'declare', 'binding', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', - 'source=source', 'destination=target', 'arguments={}', 'routing_key=blablub', 'destination_type=queue' + context 'specifying credentials' do + before :each do + @resource = Puppet::Type::Rabbitmq_binding.new( + {:name => 'source@test2@/', + :destination_type => :queue, + :routing_key => 'blablubd', + :arguments => {}, + :user => 'colin', + :password => 'secret' + } ) - provider.create + @provider = provider_class.new(@resource) end - context 'specifying credentials' do - let(:resource) do - Puppet::Type::Rabbitmq_binding.new( - name: 'source@test2@/', - destination_type: :queue, - routing_key: 'blablubd', - arguments: {}, - user: 'colin', - password: 'secret' - ) - end - let(:provider) { provider_class.new(resource) } - - it 'calls rabbitmqadmin to create' do - provider.expects(:rabbitmqadmin).with( - 'declare', 'binding', '--vhost=/', '--user=colin', '--password=secret', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', - 'source=source', 'destination=test2', 'arguments={}', 'routing_key=blablubd', 'destination_type=queue' - ) - provider.create - end - end - - context 'new queue_bindings' do - let(:resource) do - Puppet::Type::Rabbitmq_binding.new( - name: 'binding1', - source: 'exchange1', - destination: 'destqueue', - destination_type: :queue, - routing_key: 'blablubd', - arguments: {} - ) - end - let(:provider) { provider_class.new(resource) } - - it 'calls rabbitmqadmin to create' do - provider.expects(:rabbitmqadmin).with( - 'declare', 'binding', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', - 'source=exchange1', 'destination=destqueue', 'arguments={}', 'routing_key=blablubd', 'destination_type=queue' - ) - provider.create - end - end - end - - describe '#destroy' do - it 'calls rabbitmqadmin to destroy' do - provider.expects(:rabbitmqadmin).with( - 'delete', 'binding', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', - 'source=source', 'destination_type=queue', 'destination=target', 'properties_key=blablub' - ) - provider.destroy + it 'should call rabbitmqadmin to create' do + @provider.expects(:rabbitmqadmin).with('declare', 'binding', '--vhost=/', '--user=colin', '--password=secret', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'source=source', 'destination=test2', 'arguments={}', 'routing_key=blablubd', 'destination_type=queue') + @provider.create end end end