Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to 'let(:foo)' syntax (resolves rubocop warnings) #576

Merged
merged 1 commit into from
Aug 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 29 additions & 27 deletions spec/unit/puppet/provider/rabbitmq_binding/rabbitmqadmin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
end
provider_class = Puppet::Type.type(:rabbitmq_binding).provider(:rabbitmqadmin)
describe provider_class do
before do
@resource = Puppet::Type::Rabbitmq_binding.new(
let(:resource) do
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) }

describe '#instances' do
it 'returns instances' do
Expand Down Expand Up @@ -77,6 +77,17 @@
end

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
/
Expand All @@ -90,71 +101,62 @@

it 'matches' do
# Test resource to match against
@resource = Puppet::Type::Rabbitmq_binding.new(
name: 'binding1',
source: 'exchange1',
destination: '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)
provider_class.prefetch('binding1' => resource)
end
end

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')
@provider.create
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

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
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

context 'specifying credentials' do
before do
@resource = Puppet::Type::Rabbitmq_binding.new(
let(:resource) do
Puppet::Type::Rabbitmq_binding.new(
name: 'source@test2@/',
destination_type: :queue,
routing_key: 'blablubd',
arguments: {},
user: 'colin',
password: 'secret'
)
@provider = provider_class.new(@resource)
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
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
before do
@resource = Puppet::Type::Rabbitmq_binding.new(
let(:resource) do
Puppet::Type::Rabbitmq_binding.new(
name: 'binding1',
source: 'exchange1',
destination: 'destqueue',
destination_type: :queue,
routing_key: 'blablubd',
arguments: {}
)
@provider = provider_class.new(@resource)
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
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
24 changes: 12 additions & 12 deletions spec/unit/puppet/provider/rabbitmq_exchange/rabbitmqadmin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
end
provider_class = Puppet::Type.type(:rabbitmq_exchange).provider(:rabbitmqadmin)
describe provider_class do
before do
@resource = Puppet::Type::Rabbitmq_exchange.new(
let(:resource) do
Puppet::Type::Rabbitmq_exchange.new(
name: 'test.headers@/',
type: :headers,
internal: :false,
Expand All @@ -16,8 +16,8 @@
'hash-headers' => 'message-distribution-hash'
}
)
@provider = provider_class.new(@resource)
end
let(:provider) { provider_class.new(resource) }

it 'returns instances' do
provider_class.expects(:rabbitmqctl).with('-q', 'list_vhosts').returns <<-EOT
Expand All @@ -39,18 +39,18 @@
end

it 'calls rabbitmqadmin to create as guest' do
@provider.expects(:rabbitmqadmin).with('declare', 'exchange', '--vhost=/', '--user=guest', '--password=guest', 'name=test.headers', 'type=headers', 'internal=false', 'durable=true', 'auto_delete=false', 'arguments={"hash-headers":"message-distribution-hash"}', '-c', '/etc/rabbitmq/rabbitmqadmin.conf')
@provider.create
provider.expects(:rabbitmqadmin).with('declare', 'exchange', '--vhost=/', '--user=guest', '--password=guest', 'name=test.headers', 'type=headers', 'internal=false', 'durable=true', 'auto_delete=false', 'arguments={"hash-headers":"message-distribution-hash"}', '-c', '/etc/rabbitmq/rabbitmqadmin.conf')
provider.create
end

it 'calls rabbitmqadmin to destroy' do
@provider.expects(:rabbitmqadmin).with('delete', 'exchange', '--vhost=/', '--user=guest', '--password=guest', 'name=test.headers', '-c', '/etc/rabbitmq/rabbitmqadmin.conf')
@provider.destroy
provider.expects(:rabbitmqadmin).with('delete', 'exchange', '--vhost=/', '--user=guest', '--password=guest', 'name=test.headers', '-c', '/etc/rabbitmq/rabbitmqadmin.conf')
provider.destroy
end

context 'specifying credentials' do
before do
@resource = Puppet::Type::Rabbitmq_exchange.new(
let(:resource) do
Puppet::Type::Rabbitmq_exchange.new(
name: 'test.headers@/',
type: :headers,
internal: 'false',
Expand All @@ -62,12 +62,12 @@
'hash-header' => 'message-distribution-hash'
}
)
@provider = provider_class.new(@resource)
end
let(:provider) { provider_class.new(resource) }

it 'calls rabbitmqadmin to create with credentials' do
@provider.expects(:rabbitmqadmin).with('declare', 'exchange', '--vhost=/', '--user=colin', '--password=secret', 'name=test.headers', 'type=headers', 'internal=false', 'durable=true', 'auto_delete=false', 'arguments={"hash-header":"message-distribution-hash"}', '-c', '/etc/rabbitmq/rabbitmqadmin.conf')
@provider.create
provider.expects(:rabbitmqadmin).with('declare', 'exchange', '--vhost=/', '--user=colin', '--password=secret', 'name=test.headers', 'type=headers', 'internal=false', 'durable=true', 'auto_delete=false', 'arguments={"hash-header":"message-distribution-hash"}', '-c', '/etc/rabbitmq/rabbitmqadmin.conf')
provider.create
end
end
end
19 changes: 10 additions & 9 deletions spec/unit/puppet/provider/rabbitmq_plugin/rabbitmqctl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
end
provider_class = Puppet::Type.type(:rabbitmq_plugin).provider(:rabbitmqplugins)
describe provider_class do
before do
@resource = Puppet::Type::Rabbitmq_plugin.new(
let(:resource) do
Puppet::Type::Rabbitmq_plugin.new(
name: 'foo'
)
@provider = provider_class.new(@resource)
end
let(:provider) { provider_class.new(resource) }

it 'matches plugins' do
@provider.expects(:rabbitmqplugins).with('list', '-E', '-m').returns("foo\n")
expect(@provider.exists?).to eq('foo')
provider.expects(:rabbitmqplugins).with('list', '-E', '-m').returns("foo\n")
expect(provider.exists?).to eq('foo')
end
it 'calls rabbitmqplugins to enable' do
@provider.expects(:rabbitmqplugins).with('enable', 'foo')
@provider.create
provider.expects(:rabbitmqplugins).with('enable', 'foo')
provider.create
end
it 'calls rabbitmqplugins to disable' do
@provider.expects(:rabbitmqplugins).with('disable', 'foo')
@provider.destroy
provider.expects(:rabbitmqplugins).with('disable', 'foo')
provider.destroy
end
end
24 changes: 12 additions & 12 deletions spec/unit/puppet/provider/rabbitmq_queue/rabbitmqadmin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
end
provider_class = Puppet::Type.type(:rabbitmq_queue).provider(:rabbitmqadmin)
describe provider_class do
before do
@resource = Puppet::Type::Rabbitmq_queue.new(
let(:resource) do
Puppet::Type::Rabbitmq_queue.new(
name: 'test@/',
durable: :true,
auto_delete: :false,
arguments: {}
)
@provider = provider_class.new(@resource)
end
let(:provider) { provider_class.new(resource) }

it 'returns instances' do
provider_class.expects(:rabbitmqctl).with('list_vhosts', '-q').returns <<-EOT
Expand All @@ -28,31 +28,31 @@
end

it 'calls rabbitmqadmin to create' do
@provider.expects(:rabbitmqadmin).with('declare', 'queue', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'name=test', 'durable=true', 'auto_delete=false', 'arguments={}')
@provider.create
provider.expects(:rabbitmqadmin).with('declare', 'queue', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'name=test', 'durable=true', 'auto_delete=false', 'arguments={}')
provider.create
end

it 'calls rabbitmqadmin to destroy' do
@provider.expects(:rabbitmqadmin).with('delete', 'queue', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'name=test')
@provider.destroy
provider.expects(:rabbitmqadmin).with('delete', 'queue', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'name=test')
provider.destroy
end

context 'specifying credentials' do
before do
@resource = Puppet::Type::Rabbitmq_queue.new(
let(:resource) do
Puppet::Type::Rabbitmq_queue.new(
name: 'test@/',
durable: 'true',
auto_delete: 'false',
arguments: {},
user: 'colin',
password: 'secret'
)
@provider = provider_class.new(@resource)
end
let(:provider) { provider_class.new(resource) }

it 'calls rabbitmqadmin to create' do
@provider.expects(:rabbitmqadmin).with('declare', 'queue', '--vhost=/', '--user=colin', '--password=secret', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'name=test', 'durable=true', 'auto_delete=false', 'arguments={}')
@provider.create
provider.expects(:rabbitmqadmin).with('declare', 'queue', '--vhost=/', '--user=colin', '--password=secret', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'name=test', 'durable=true', 'auto_delete=false', 'arguments={}')
provider.create
end
end
end
Loading