X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Frabbitmq%2Fspec%2Funit%2Fpuppet%2Fprovider%2Frabbitmq_policy%2Frabbitmqctl_spec.rb;h=075602c89363dcbd37edd8f315bbb0f01febce3a;hb=94a8783f522bbf2996cb8a59b977dea583e8b0c7;hp=cddb6c0c0ed13efafde7442036c75162a3686ff4;hpb=e107504bce7d9b21cc301124fc7c39fdb0762374;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/rabbitmq/spec/unit/puppet/provider/rabbitmq_policy/rabbitmqctl_spec.rb b/3rdparty/modules/rabbitmq/spec/unit/puppet/provider/rabbitmq_policy/rabbitmqctl_spec.rb index cddb6c0c0..075602c89 100644 --- a/3rdparty/modules/rabbitmq/spec/unit/puppet/provider/rabbitmq_policy/rabbitmqctl_spec.rb +++ b/3rdparty/modules/rabbitmq/spec/unit/puppet/provider/rabbitmq_policy/rabbitmqctl_spec.rb @@ -1,113 +1,136 @@ -require 'puppet' -require 'mocha' - -RSpec.configure do |config| - config.mock_with :mocha -end +require 'spec_helper' describe Puppet::Type.type(:rabbitmq_policy).provider(:rabbitmqctl) do - let(:resource) do Puppet::Type.type(:rabbitmq_policy).new( - :name => 'ha-all@/', - :pattern => '.*', - :definition => { + name: 'ha-all@/', + pattern: '.*', + definition: { 'ha-mode' => 'all' - }, - :provider => described_class.name + } ) end + let(:provider) { described_class.new(resource) } - let(:provider) { resource.provider } - - after(:each) do + after do described_class.instance_variable_set(:@policies, nil) end - it 'should accept @ in policy name' do - resource = Puppet::Type.type(:rabbitmq_policy).new( - :name => 'ha@home@/', - :pattern => '.*', - :definition => { - 'ha-mode' => 'all' - }, - :provider => described_class.name - ) - provider = described_class.new(resource) - provider.should_policy.should == 'ha@home' - provider.should_vhost.should == '/' + context 'has "@" in policy name' do + let(:resource) do + Puppet::Type.type(:rabbitmq_policy).new( + name: 'ha@home@/', + pattern: '.*', + definition: { + 'ha-mode' => 'all' + }, + provider: described_class.name + ) + end + let(:provider) { described_class.new(resource) } + + it do + expect(provider.should_policy).to eq('ha@home') + end + + it do + expect(provider.should_vhost).to eq('/') + end end - it 'should fail with invalid output from list' do + it 'fails with invalid output from list' do + provider.class.expects(:rabbitmqctl).with('-q', 'status').returns '{rabbit,"RabbitMQ","3.1.5"}' provider.class.expects(:rabbitmqctl).with('list_policies', '-q', '-p', '/').returns 'foobar' - expect { provider.exists? }.to raise_error(Puppet::Error, /cannot parse line from list_policies/) + expect { provider.exists? }.to raise_error(Puppet::Error, %r{cannot parse line from list_policies}) end - it 'should match policies from list (>=3.2.0)' do - provider.class.expects(:rabbitmqctl).with('list_policies', '-q', '-p', '/').returns <<-EOT + context 'with RabbitMQ version >=3.7.0' do + it 'matches policies from list' do + provider.class.expects(:rabbitmq_version).returns '3.7.0' + provider.class.expects(:rabbitmqctl).with('list_policies', '-q', '-p', '/').returns <<-EOT +/ ha-all .* all {"ha-mode":"all","ha-sync-mode":"automatic"} 0 +/ test .* exchanges {"ha-mode":"all"} 0 +EOT + expect(provider.exists?).to eq(applyto: 'all', + pattern: '.*', + priority: '0', + definition: { + 'ha-mode' => 'all', + 'ha-sync-mode' => 'automatic' + }) + end + end + + context 'with RabbitMQ version >=3.2.0 and < 3.7.0' do + it 'matches policies from list' do + provider.class.expects(:rabbitmq_version).returns '3.6.9' + provider.class.expects(:rabbitmqctl).with('list_policies', '-q', '-p', '/').returns <<-EOT / ha-all all .* {"ha-mode":"all","ha-sync-mode":"automatic"} 0 / test exchanges .* {"ha-mode":"all"} 0 EOT - provider.exists?.should == { - :applyto => 'all', - :pattern => '.*', - :priority => '0', - :definition => { - 'ha-mode' => 'all', - 'ha-sync-mode' => 'automatic'} - } + expect(provider.exists?).to eq(applyto: 'all', + pattern: '.*', + priority: '0', + definition: { + 'ha-mode' => 'all', + 'ha-sync-mode' => 'automatic' + }) + end end - it 'should match policies from list (<3.2.0)' do - provider.class.expects(:rabbitmqctl).with('list_policies', '-q', '-p', '/').returns <<-EOT + context 'with RabbitMQ version <3.2.0' do + it 'matches policies from list (<3.2.0)' do + provider.class.expects(:rabbitmq_version).returns '3.1.5' + provider.class.expects(:rabbitmqctl).with('list_policies', '-q', '-p', '/').returns <<-EOT / ha-all .* {"ha-mode":"all","ha-sync-mode":"automatic"} 0 / test .* {"ha-mode":"all"} 0 EOT - provider.exists?.should == { - :applyto => 'all', - :pattern => '.*', - :priority => '0', - :definition => { - 'ha-mode' => 'all', - 'ha-sync-mode' => 'automatic'} - } + expect(provider.exists?).to eq(applyto: 'all', + pattern: '.*', + priority: '0', + definition: { + 'ha-mode' => 'all', + 'ha-sync-mode' => 'automatic' + }) + end end - it 'should not match an empty list' do + it 'does not match an empty list' do + provider.class.expects(:rabbitmqctl).with('-q', 'status').returns '{rabbit,"RabbitMQ","3.1.5"}' provider.class.expects(:rabbitmqctl).with('list_policies', '-q', '-p', '/').returns '' - provider.exists?.should == nil + expect(provider.exists?).to eq(nil) end - it 'should destroy policy' do + it 'destroys policy' do provider.expects(:rabbitmqctl).with('clear_policy', '-p', '/', 'ha-all') provider.destroy end - it 'should only call set_policy once (<3.2.0)' do + it 'onlies call set_policy once (<3.2.0)' do provider.class.expects(:rabbitmq_version).returns '3.1.0' provider.resource[:priority] = '10' provider.resource[:applyto] = 'exchanges' provider.expects(:rabbitmqctl).with('set_policy', - '-p', '/', - 'ha-all', - '.*', - '{"ha-mode":"all"}', - '10').once + '-p', '/', + 'ha-all', + '.*', + '{"ha-mode":"all"}', + '10').once provider.priority = '10' provider.applyto = 'exchanges' end - it 'should only call set_policy once (>=3.2.0)' do + it 'onlies call set_policy once (>=3.2.0)' do provider.class.expects(:rabbitmq_version).returns '3.2.0' provider.resource[:priority] = '10' provider.resource[:applyto] = 'exchanges' provider.expects(:rabbitmqctl).with('set_policy', - '-p', '/', - '--priority', '10', - '--apply-to', 'exchanges', - 'ha-all', - '.*', - '{"ha-mode":"all"}').once + '-p', '/', + '--priority', '10', + '--apply-to', 'exchanges', + 'ha-all', + '.*', + '{"ha-mode":"all"}').once provider.priority = '10' provider.applyto = 'exchanges' end