add hash/array support for upstream_cfg_prepend

This commit is contained in:
Daniel Black 2014-03-12 19:06:47 +11:00
parent b27e446b3a
commit 5829559aca
2 changed files with 17 additions and 1 deletions

View file

@ -36,11 +36,19 @@ describe 'nginx::resource::upstream' do
'test3' => 'test value 3',
'test1' => 'test value 1',
'test2' => 'test value 2',
'test4' => ['test value 1', 'test value 2'],
'test5' => {'subkey1' => 'subvalue1'},
'test6' => {'subkey1' => ['subvalue1', 'subvalue2']},
},
:match => [
' test1 test value 1;',
' test2 test value 2;',
' test3 test value 3;',
' test4 test value 1;',
' test4 test value 2;',
' test5 subkey1 subvalue1;',
' test6 subkey1 subvalue1;',
' test6 subkey1 subvalue2;',
],
},
{

View file

@ -1,6 +1,14 @@
upstream <%= @name %> {
<% if @upstream_cfg_prepend -%><% @upstream_cfg_prepend.sort_by{|k,v| k}.each do |key,value| %>
<%= key %> <%= value %>;
<% if value.is_a?(Hash) -%><% value.each do |subkey,subvalue| -%>
<% Array(subvalue).each do |asubvalue| -%>
<%= key %> <%= subkey %> <%= asubvalue %>;
<% end -%>
<% end -%><% else -%>
<% Array(value).each do |asubvalue| -%>
<%= key %> <%= asubvalue %>;
<% end -%>
<% end -%>
<% end -%><% end -%>
<% @members.each do |i| %>
server <%= i %> fail_timeout=<%= @upstream_fail_timeout %>;<% end %>