Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fatmcgav committed Aug 16, 2017
1 parent b62e944 commit 1dfa47b
Showing 1 changed file with 126 additions and 16 deletions.
142 changes: 126 additions & 16 deletions spec/unit/puppet/provider/rabbitmq_binding/rabbitmqadmin_spec.rb
Expand Up @@ -7,24 +7,111 @@
describe provider_class do
before :each do
@resource = Puppet::Type::Rabbitmq_binding.new(
{:name => 'source@target@/',
:destination_type => :queue,
:routing_key => 'blablub',
:arguments => {}
{
:name => 'source@target@/',
:destination_type => :queue,
:routing_key => 'blablub',
:arguments => {}
}
)
@provider = provider_class.new(@resource)
end

it 'should return instances' do
provider_class.expects(:rabbitmqctl).with('list_vhosts', '-q').returns <<-EOT
describe "#instances" do
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
queue queue queue []
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
instances = provider_class.instances
instances.size.should == 1
instances = provider_class.instances
instances.size.should == 1
instances.map do |prov|
{
:source => prov.get(:source),
:dest => prov.get(:dest),
:vhost => prov.get(:vhost),
:routing_key => prov.get(:routing_key)
}
end.should == [
{
:source => 'exchange',
:dest => 'dst_queue',
:vhost => '/',
:routing_key => '*'
}
]
end

it 'should return 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
instances.size.should == 2
instances.map do |prov|
{
:source => prov.get(:source),
:dest => prov.get(:dest),
:vhost => prov.get(:vhost),
:routing_key => prov.get(:routing_key)
}
end.should == [
{
:source => 'exchange',
:dest => 'dst_queue',
:vhost => '/',
:routing_key => 'routing_one'
},
{
:source => 'exchange',
:dest => 'dst_queue',
:vhost => '/',
:routing_key => 'routing_two'
}
]
end
end

describe "#prefetch" do
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
@resource = Puppet::Type::Rabbitmq_binding.new(
{
:name => 'binding1',
:source => 'exchange1',
:dest => 'destqueue',
:destination_type => :queue,
:routing_key => 'blablubd',
:arguments => {}
}
)

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
end

it 'should call rabbitmqadmin to create' do
Expand All @@ -40,12 +127,13 @@
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'
{
:name => 'source@test2@/',
:destination_type => :queue,
:routing_key => 'blablubd',
:arguments => {},
:user => 'colin',
:password => 'secret'
}
)
@provider = provider_class.new(@resource)
Expand All @@ -56,4 +144,26 @@
@provider.create
end
end

context 'new queue_bindings' do
before :each do
@resource = Puppet::Type::Rabbitmq_binding.new(
{
:name => 'binding1',
:source => 'exchange1',
:dest => 'destqueue',
:destination_type => :queue,
:routing_key => 'blablubd',
:arguments => {}
}
)
@provider = provider_class.new(@resource)
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=exchange1', 'destination=destqueue', 'arguments={}', 'routing_key=blablubd', 'destination_type=queue')
@provider.create
end
end

end

0 comments on commit 1dfa47b

Please sign in to comment.