From f9e56b6d4308da2b298b6b616313ecc553a5b6dc Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Sun, 8 Jul 2012 21:33:13 -0700 Subject: Properly handle both Arrays and Strings passed as balancer member options The template cannot rely on deprecated functionality of the String class (`#each` which disappears in 1.9) Fixes #9 --- spec/defines/balancermember_spec.rb | 43 ++++++++++++++++++++++++++---------- templates/haproxy_balancermember.erb | 5 ++++- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/spec/defines/balancermember_spec.rb b/spec/defines/balancermember_spec.rb index 75b761e..4566ca4 100644 --- a/spec/defines/balancermember_spec.rb +++ b/spec/defines/balancermember_spec.rb @@ -7,17 +7,36 @@ describe 'haproxy::balancermember' do :hostname => 'dero' } end - let(:params) do - { :name => 'tyler', - :listening_service => 'croy', - :balancer_port => '18140', - :balancermember_options => 'check' - } + + context 'with a single balancermember option' do + let(:params) do + { :name => 'tyler', + :listening_service => 'croy', + :balancer_port => '18140', + :balancermember_options => 'check' + } + end + + it { should contain_concat__fragment('croy_balancermember_tyler').with( + 'order' => '20', + 'target' => '/etc/haproxy/haproxy.cfg', + 'content' => " server dero 1.1.1.1:18140 check\n" + ) } end - it { should contain_concat__fragment('croy_balancermember_tyler').with( - 'order' => '20', - 'target' => '/etc/haproxy/haproxy.cfg', - 'content' => " server dero 1.1.1.1:18140 check \n" - ) } -end \ No newline at end of file + context 'with multiple balancermember options' do + let(:params) do + { :name => 'tyler', + :listening_service => 'croy', + :balancer_port => '18140', + :balancermember_options => ['check', 'close'] + } + end + + it { should contain_concat__fragment('croy_balancermember_tyler').with( + 'order' => '20', + 'target' => '/etc/haproxy/haproxy.cfg', + 'content' => " server dero 1.1.1.1:18140 check close\n" + ) } + end +end diff --git a/templates/haproxy_balancermember.erb b/templates/haproxy_balancermember.erb index b739e11..f85137d 100644 --- a/templates/haproxy_balancermember.erb +++ b/templates/haproxy_balancermember.erb @@ -1 +1,4 @@ - server <%= server_name %> <%= balancer_ip %>:<%= balancer_port %> <% balancermember_options.each do |item| %> <%= item %> <% end %> + server <%= server_name %> <%= balancer_ip %>:<%= balancer_port %> <% + items = balancermember_options + items = [items] unless balancermember_options.instance_of? Array + items.each do |item| %> <%= item %><% end %> -- cgit v1.2.3