Skip to content

Commit

Permalink
Allow ha-sync-batch-size for rabbitmq_policy definition to be integer (
Browse files Browse the repository at this point in the history
…voxpupuli#500)

* Update rabbitmq_policy.rb

* Update rabbitmq_policy_spec.rb
  • Loading branch information
mxftw authored and tphoney committed Sep 1, 2016
1 parent daed6b3 commit 2582fa2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/puppet/type/rabbitmq_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ def validate_definition(definition)
raise ArgumentError, "Invalid shards-per-node value '#{shards_per_node_val}'"
end
end
if definition.key? 'ha-sync-batch-size'
ha_sync_batch_size_val = definition['ha-sync-batch-size']
unless ha_sync_batch_size_val.to_i.to_s == ha_sync_batch_size_val
raise ArgumentError, "Invalid ha-sync-batch-size value '#{ha_sync_batch_size_val}'"
end
end
end

def munge_definition(definition)
Expand All @@ -123,6 +129,9 @@ def munge_definition(definition)
if definition.key? 'shards-per-node'
definition['shards-per-node'] = definition['shards-per-node'].to_i
end
if definition.key? 'ha-sync-batch-size'
definition['ha-sync-batch-size'] = definition['ha-sync-batch-size'].to_i
end
definition
end
end
14 changes: 14 additions & 0 deletions spec/unit/puppet/type/rabbitmq_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,18 @@
@policy[:definition] = definition
}.to raise_error(Puppet::Error, /Invalid shards-per-node value.*future/)
end

it 'should accept and convert the ha-sync-batch-size value' do
definition = {'ha-sync-batch-size' => '1800000'}
@policy[:definition] = definition
@policy[:definition]['ha-sync-batch-size'].should be_a(Fixnum)
@policy[:definition]['ha-sync-batch-size'].should == 1800000
end

it 'should not accept non-numeric ha-sync-batch-size value' do
definition = {'ha-sync-batch-size' => 'future'}
expect {
@policy[:definition] = definition
}.to raise_error(Puppet::Error, /Invalid ha-sync-batch-size value.*future/)
end
end

0 comments on commit 2582fa2

Please sign in to comment.