Skip to content

Commit

Permalink
Merge pull request #865 from joec4i/skip_munging
Browse files Browse the repository at this point in the history
Add new parameter autoconvert for rabbitmq_parameter
  • Loading branch information
wyardley authored Nov 27, 2020
2 parents c8aea9a + d7cc1e0 commit 5c28cc6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/puppet/type/rabbitmq_parameter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@
'expires' => '360000',
},
}
rabbitmq_parameter { 'documentumShovelNoMunging@/':
component_name => '',
value => {
'src-uri' => 'amqp://',
'src-exchange' => 'my-exchange',
'src-exchange-key' => '6',
'src-queue' => 'my-queue',
'dest-uri' => 'amqp://remote-server',
'dest-exchange' => 'another-exchange',
},
autoconvert => false,
}
DESC

ensurable do
Expand Down Expand Up @@ -50,6 +62,12 @@
end
end

newparam(:autoconvert) do
desc 'whether numeric strings from `value` should be converted to int automatically'
newvalues(:true, :false)
defaultto(:true)
end

newproperty(:value) do
desc 'A hash of values to use with the component name you are setting'
validate do |value|
Expand Down Expand Up @@ -78,6 +96,7 @@ def validate_value(value)
end

def munge_value(value)
return value if self[:autoconvert] == :false
value.each do |k, v|
value[k] = v.to_i if v =~ %r{\A[-+]?[0-9]+\z}
end
Expand Down
8 changes: 8 additions & 0 deletions spec/unit/puppet/type/rabbitmq_parameter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,12 @@
parameter[:value] = value
expect(parameter[:value]['myparameter']).to eq(1_800_000)
end

it 'does not convert numeric string to integer when autoconvert is set to false' do
parameter[:autoconvert] = false
value = { 'myparameter' => '1800000' }
parameter[:value] = value
expect(parameter[:value]['myparameter']).to eq('1800000')
expect(parameter[:value]['myparameter']).to be_kind_of(String)
end
end

0 comments on commit 5c28cc6

Please sign in to comment.