summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorR. Tyler Croy <tyler@monkeypox.org>2012-07-08 21:33:13 -0700
committerR. Tyler Croy <tyler@monkeypox.org>2012-07-08 21:38:49 -0700
commitf9e56b6d4308da2b298b6b616313ecc553a5b6dc (patch)
treeef4d3c6f012b5adcfc6b35364d06c370ccf95170
parenteb482ec09f20a6d3a1ec6539bf65167478284a04 (diff)
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
-rw-r--r--spec/defines/balancermember_spec.rb43
-rw-r--r--templates/haproxy_balancermember.erb5
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 %>