From 9fdfd0cf193ea67b5d980c68a1a8156ab831e4ce Mon Sep 17 00:00:00 2001 From: James Beattie Date: Tue, 31 Oct 2023 15:19:16 +1100 Subject: [PATCH] Treat `initial-cluster-size` option in policy as an integer --- lib/puppet/type/rabbitmq_policy.rb | 5 +++++ spec/unit/puppet/type/rabbitmq_policy_spec.rb | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/puppet/type/rabbitmq_policy.rb b/lib/puppet/type/rabbitmq_policy.rb index 7ec5e827a..c7b49a6d8 100644 --- a/lib/puppet/type/rabbitmq_policy.rb +++ b/lib/puppet/type/rabbitmq_policy.rb @@ -124,6 +124,10 @@ def validate_definition(definition) delivery_limit_val = definition['delivery-limit'] raise ArgumentError, "Invalid delivery-limit value '#{delivery_limit_val}'" unless delivery_limit_val.to_i.to_s == delivery_limit_val end + if definition.key? 'initial-cluster-size' # rubocop:disable Style/GuardClause + initial_cluster_size_val = definition['initial-cluster-size'] + raise ArgumentError, "Invalid initial-cluster-size value '#{initial_cluster_size_val}'" unless initial_cluster_size_val.to_i.to_s == initial_cluster_size_val + end end def munge_definition(definition) @@ -135,6 +139,7 @@ def munge_definition(definition) definition['shards-per-node'] = definition['shards-per-node'].to_i if definition.key? 'shards-per-node' definition['ha-sync-batch-size'] = definition['ha-sync-batch-size'].to_i if definition.key? 'ha-sync-batch-size' definition['delivery-limit'] = definition['delivery-limit'].to_i if definition.key? 'delivery-limit' + definition['initial-cluster-size'] = definition['initial-cluster-size'].to_i if definition.key? 'initial-cluster-size' definition end end diff --git a/spec/unit/puppet/type/rabbitmq_policy_spec.rb b/spec/unit/puppet/type/rabbitmq_policy_spec.rb index 4dfe7638f..e8f77bf68 100644 --- a/spec/unit/puppet/type/rabbitmq_policy_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_policy_spec.rb @@ -195,6 +195,19 @@ end.to raise_error(Puppet::Error, %r{Invalid delivery-limit value.*future}) end + it 'accepts and converts the initial-cluster-size value' do + definition = { 'initial-cluster-size' => '3' } + policy[:definition] = definition + expect(policy[:definition]['initial-cluster-size']).to eq(3) + end + + it 'does not accept non-numeric initial-cluster-size value' do + definition = { 'initial-cluster-size' => 'impressive' } + expect do + policy[:definition] = definition + end.to raise_error(Puppet::Error, %r{Invalid initial-cluster-size value.*future}) + end + context 'accepts list value in ha-params when ha-mode = nodes' do before do policy[:definition] = definition