X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Frabbitmq%2Fspec%2Funit%2Fpuppet%2Ftype%2Frabbitmq_policy_spec.rb;fp=3rdparty%2Fmodules%2Frabbitmq%2Fspec%2Funit%2Fpuppet%2Ftype%2Frabbitmq_policy_spec.rb;h=fca3c6142c8be86f81cd60d6e1f102cc0c2e5b1b;hb=921e69100a563cf143f56a3905d8362336d939ff;hp=36bf2a73fab8be6a53753bf05647ce5e7a4da261;hpb=b54f52d2899c5785923c804fdfbba0782c147da4;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/rabbitmq/spec/unit/puppet/type/rabbitmq_policy_spec.rb b/3rdparty/modules/rabbitmq/spec/unit/puppet/type/rabbitmq_policy_spec.rb index 36bf2a73f..fca3c6142 100644 --- a/3rdparty/modules/rabbitmq/spec/unit/puppet/type/rabbitmq_policy_spec.rb +++ b/3rdparty/modules/rabbitmq/spec/unit/puppet/type/rabbitmq_policy_spec.rb @@ -1,119 +1,202 @@ -require 'puppet' -require 'puppet/type/rabbitmq_policy' - +require 'spec_helper' describe Puppet::Type.type(:rabbitmq_policy) do - - before do - @policy = Puppet::Type.type(:rabbitmq_policy).new( - :name => 'ha-all@/', - :pattern => '.*', - :definition => { + let(:policy) do + Puppet::Type.type(:rabbitmq_policy).new( + name: 'ha-all@/', + pattern: '.*', + definition: { 'ha-mode' => 'all' - }) + } + ) end - it 'should accept a valid name' do - @policy[:name] = 'ha-all@/' - @policy[:name].should == 'ha-all@/' + it 'accepts a valid name' do + policy[:name] = 'ha-all@/' + expect(policy[:name]).to eq('ha-all@/') end - it 'should require a name' do - expect { + it 'requires a name' do + expect do Puppet::Type.type(:rabbitmq_policy).new({}) - }.to raise_error(Puppet::Error, 'Title or name must be provided') + end.to raise_error(Puppet::Error, 'Title or name must be provided') end - it 'should fail when name does not have a @' do - expect { - @policy[:name] = 'ha-all' - }.to raise_error(Puppet::Error, /Valid values match/) + it 'fails when name does not have a @' do + expect do + policy[:name] = 'ha-all' + end.to raise_error(Puppet::Error, %r{Valid values match}) end - it 'should accept a valid regex for pattern' do - @policy[:pattern] = '.*?' - @policy[:pattern].should == '.*?' + it 'accepts a valid regex for pattern' do + policy[:pattern] = '.*?' + expect(policy[:pattern]).to eq('.*?') end - it 'should accept an empty string for pattern' do - @policy[:pattern] = '' - @policy[:pattern].should == '' + it 'accepts an empty string for pattern' do + policy[:pattern] = '' + expect(policy[:pattern]).to eq('') end - it 'should not accept invalid regex for pattern' do - expect { - @policy[:pattern] = '*' - }.to raise_error(Puppet::Error, /Invalid regexp/) + it 'does not accept invalid regex for pattern' do + expect do + policy[:pattern] = '*' + end.to raise_error(Puppet::Error, %r{Invalid regexp}) end - it 'should accept valid value for applyto' do + it 'accepts valid value for applyto' do [:all, :exchanges, :queues].each do |v| - @policy[:applyto] = v - @policy[:applyto].should == v + policy[:applyto] = v + expect(policy[:applyto]).to eq(v) end end - it 'should not accept invalid value for applyto' do - expect { - @policy[:applyto] = 'me' - }.to raise_error(Puppet::Error, /Invalid value/) + it 'does not accept invalid value for applyto' do + expect do + policy[:applyto] = 'me' + end.to raise_error(Puppet::Error, %r{Invalid value}) end - it 'should accept a valid hash for definition' do - definition = {'ha-mode' => 'all', 'ha-sync-mode' => 'automatic'} - @policy[:definition] = definition - @policy[:definition].should == definition + it 'accepts a valid hash for definition' do + definition = { 'ha-mode' => 'all', 'ha-sync-mode' => 'automatic' } + policy[:definition] = definition + expect(policy[:definition]).to eq(definition) end - it 'should not accept invalid hash for definition' do - expect { - @policy[:definition] = 'ha-mode' - }.to raise_error(Puppet::Error, /Invalid definition/) + it 'does not accept a string for definition' do + expect do + policy[:definition] = 'ha-mode' + end.to raise_error(Puppet::Error, %r{Invalid definition}) + end - expect { - @policy[:definition] = {'ha-mode' => ['a', 'b']} - }.to raise_error(Puppet::Error, /Invalid definition/) + it 'does not accept invalid hash for definition' do + expect do + policy[:definition] = { 'ha-mode' => %w[a b] } + end.to raise_error(Puppet::Error, %r{Invalid definition}) end - it 'should accept valid value for priority' do + it 'accepts valid value for priority' do [0, 10, '0', '10'].each do |v| - @policy[:priority] = v - @policy[:priority].should == v + policy[:priority] = v + expect(policy[:priority]).to eq(v) end end - it 'should not accept invalid value for priority' do + it 'does not accept invalid value for priority' do ['-1', -1, '1.0', 1.0, 'abc', ''].each do |v| - expect { - @policy[:priority] = v - }.to raise_error(Puppet::Error, /Invalid value/) + expect do + policy[:priority] = v + end.to raise_error(Puppet::Error, %r{Invalid value}) end end - it 'should accept and convert ha-params for ha-mode exactly' do - definition = {'ha-mode' => 'exactly', 'ha-params' => '2'} - @policy[:definition] = definition - @policy[:definition]['ha-params'].should be_a(Fixnum) - @policy[:definition]['ha-params'].should == 2 + it 'accepts and convert ha-params for ha-mode exactly' do + definition = { 'ha-mode' => 'exactly', 'ha-params' => '2' } + policy[:definition] = definition + expect(policy[:definition]['ha-params']).to eq(2) + end + + it 'does not accept non-numeric ha-params for ha-mode exactly' do + definition = { 'ha-mode' => 'exactly', 'ha-params' => 'nonnumeric' } + expect do + policy[:definition] = definition + end.to raise_error(Puppet::Error, %r{Invalid ha-params.*nonnumeric.*exactly}) + end + + it 'accepts and convert the expires value' do + definition = { 'expires' => '1800000' } + policy[:definition] = definition + expect(policy[:definition]['expires']).to eq(1_800_000) + end + + it 'does not accept non-numeric expires value' do + definition = { 'expires' => 'future' } + expect do + policy[:definition] = definition + end.to raise_error(Puppet::Error, %r{Invalid expires value.*future}) + end + + it 'accepts and convert the message-ttl value' do + definition = { 'message-ttl' => '1800000' } + policy[:definition] = definition + expect(policy[:definition]['message-ttl']).to eq(1_800_000) + end + + it 'does not accept non-numeric message-ttl value' do + definition = { 'message-ttl' => 'future' } + expect do + policy[:definition] = definition + end.to raise_error(Puppet::Error, %r{Invalid message-ttl value.*future}) + end + + it 'accepts and convert the max-length value' do + definition = { 'max-length' => '1800000' } + policy[:definition] = definition + expect(policy[:definition]['max-length']).to eq(1_800_000) end - it 'should not accept non-numeric ha-params for ha-mode exactly' do - definition = {'ha-mode' => 'exactly', 'ha-params' => 'nonnumeric'} - expect { - @policy[:definition] = definition - }.to raise_error(Puppet::Error, /Invalid ha-params.*nonnumeric.*exactly/) + it 'does not accept non-numeric max-length value' do + definition = { 'max-length' => 'future' } + expect do + policy[:definition] = definition + end.to raise_error(Puppet::Error, %r{Invalid max-length value.*future}) end - it 'should accept and convert the expires value' do - definition = {'expires' => '1800000'} - @policy[:definition] = definition - @policy[:definition]['expires'].should be_a(Fixnum) - @policy[:definition]['expires'].should == 1800000 + it 'accepts and convert the max-length-bytes value' do + definition = { 'max-length-bytes' => '1800000' } + policy[:definition] = definition + expect(policy[:definition]['max-length-bytes']).to eq(1_800_000) + end + + it 'does not accept non-numeric max-length-bytes value' do + definition = { 'max-length-bytes' => 'future' } + expect do + policy[:definition] = definition + end.to raise_error(Puppet::Error, %r{Invalid max-length-bytes value.*future}) + end + + it 'accepts and convert the shards-per-node value' do + definition = { 'shards-per-node' => '1800000' } + policy[:definition] = definition + expect(policy[:definition]['shards-per-node']).to eq(1_800_000) + end + + it 'does not accept non-numeric shards-per-node value' do + definition = { 'shards-per-node' => 'future' } + expect do + policy[:definition] = definition + end.to raise_error(Puppet::Error, %r{Invalid shards-per-node value.*future}) + end + + it 'accepts and convert the ha-sync-batch-size value' do + definition = { 'ha-sync-batch-size' => '1800000' } + policy[:definition] = definition + expect(policy[:definition]['ha-sync-batch-size']).to eq(1_800_000) + end + + it 'does not accept non-numeric ha-sync-batch-size value' do + definition = { 'ha-sync-batch-size' => 'future' } + expect do + policy[:definition] = definition + end.to raise_error(Puppet::Error, %r{Invalid ha-sync-batch-size value.*future}) + end + + context 'accepts list value in ha-params when ha-mode = nodes' do + before do + policy[:definition] = definition + end + + let(:definition) { { 'ha-mode' => 'nodes', 'ha-params' => ['rabbit@rabbit-01', 'rabbit@rabbit-02'] } } + + it { expect(policy[:definition]['ha-mode']).to eq('nodes') } + it { expect(policy[:definition]['ha-params']).to be_a(Array) } + it { expect(policy[:definition]['ha-params'][0]).to eq('rabbit@rabbit-01') } + it { expect(policy[:definition]['ha-params'][1]).to eq('rabbit@rabbit-02') } end - it 'should not accept non-numeric expires value' do - definition = {'expires' => 'future'} - expect { - @policy[:definition] = definition - }.to raise_error(Puppet::Error, /Invalid expires value.*future/) + it 'does not accept non-list value in ha-params when ha-mode = nodes' do + definition = { 'ha-mode' => 'nodes', 'ha-params' => 'this-will-fail' } + expect do + policy[:definition] = definition + end.to raise_error(Puppet::Error, %r{Invalid definition, value this-will-fail for key ha-params is not an array}) end end