diff --git a/lib/puppet/type/rabbitmq_policy.rb b/lib/puppet/type/rabbitmq_policy.rb index 794a12455..259a1d66c 100644 --- a/lib/puppet/type/rabbitmq_policy.rb +++ b/lib/puppet/type/rabbitmq_policy.rb @@ -43,6 +43,9 @@ validate do |value| resource.validate_definition(value) end + munge do |value| + resource.munge_definition(value) + end end newproperty(:priority) do @@ -72,21 +75,27 @@ def validate_definition(definition) raise ArgumentError, "Invalid definition" end end - # If ha-mode is 'exactly', convert ha-params to integer if definition['ha-mode'] == 'exactly' ha_params = definition['ha-params'] unless ha_params.to_i.to_s == ha_params raise ArgumentError, "Invalid ha-params '#{ha_params}' for ha-mode 'exactly'" end - definition['ha-params'] = ha_params.to_i end - if definition.key? 'expires' expires_val = definition['expires'] unless expires_val.to_i.to_s == expires_val raise ArgumentError, "Invalid expires value '#{expires_val}'" end - definition['expires'] = expires_val.to_i end end + + def munge_definition(definition) + if definition['ha-mode'] == 'exactly' + definition['ha-params'] = definition['ha-params'].to_i + end + if definition.key? 'expires' + definition['expires'] = definition['expires'].to_i + end + definition + end end diff --git a/spec/unit/puppet/type/rabbitmq_policy_spec.rb b/spec/unit/puppet/type/rabbitmq_policy_spec.rb index bd5e832e3..36bf2a73f 100644 --- a/spec/unit/puppet/type/rabbitmq_policy_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_policy_spec.rb @@ -93,6 +93,7 @@ definition = {'ha-mode' => 'exactly', 'ha-params' => '2'} @policy[:definition] = definition @policy[:definition]['ha-params'].should be_a(Fixnum) + @policy[:definition]['ha-params'].should == 2 end it 'should not accept non-numeric ha-params for ha-mode exactly' do @@ -106,6 +107,7 @@ definition = {'expires' => '1800000'} @policy[:definition] = definition @policy[:definition]['expires'].should be_a(Fixnum) + @policy[:definition]['expires'].should == 1800000 end it 'should not accept non-numeric expires value' do