Skip to content

Commit

Permalink
Allow Array values in rabbitmq_parameter
Browse files Browse the repository at this point in the history
Array (lists) are allowed values to use with rabbitmqctl.

For example: src-uri when setting up a shovel.
  • Loading branch information
vStone committed Feb 7, 2019
1 parent 5283ed8 commit 1fc5a66
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/type/rabbitmq_parameter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def validate_component_name(value)
def validate_value(value)
raise ArgumentError, 'Invalid value' unless [Hash].include?(value.class)
value.each do |_k, v|
unless [String, TrueClass, FalseClass].include?(v.class)
unless [String, TrueClass, FalseClass, Array].include?(v.class)
raise ArgumentError, 'Invalid value'
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@

it 'matches parameters from list' do
provider.class.expects(:rabbitmqctl_list).with('parameters', '-p', '/').returns <<-EOT
shovel documentumShovel {"src-uri":"amqp://","src-queue":"my-queue","dest-uri":"amqp://remote-server","dest-queue":"another-queue"}
shovel documentumShovel {"src-uri":["amqp://cl1","amqp://cl2"],"src-queue":"my-queue","dest-uri":"amqp://remote-server","dest-queue":"another-queue"}
EOT
expect(provider.exists?).to eq(component_name: 'shovel',
value: {
'src-uri' => 'amqp://',
'src-uri' => ['amqp://cl1', 'amqp://cl2'],
'src-queue' => 'my-queue',
'dest-uri' => 'amqp://remote-server',
'dest-queue' => 'another-queue'
Expand Down
10 changes: 8 additions & 2 deletions spec/unit/puppet/type/rabbitmq_parameter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,18 @@
end.to raise_error(Puppet::Error, %r{Invalid value})
end

it 'does not accept an array for definition' do
it 'does not accept an object for definition' do
expect do
parameter[:value] = { 'message-ttl' => %w[999 100] }
parameter[:value] = { 'message-ttl' => Object.new }
end.to raise_error(Puppet::Error, %r{Invalid value})
end

it 'accepts array as myparameter' do
value = { 'myparameter' => %w[my string] }
parameter[:value] = value
expect(parameter[:value]['myparameter']).to eq(%w[my string])
end

it 'accepts string as myparameter' do
value = { 'myparameter' => 'mystring' }
parameter[:value] = value
Expand Down

0 comments on commit 1fc5a66

Please sign in to comment.