Skip to content

Commit

Permalink
allow try_files and index in location resource (#966)
Browse files Browse the repository at this point in the history
  • Loading branch information
wyardley authored and jyaworski committed Nov 10, 2016
1 parent bcb17f2 commit 1421b4c
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 18 deletions.
4 changes: 3 additions & 1 deletion manifests/resource/location.pp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@
if ($autoindex != undef) {
validate_string($autoindex)
}
validate_array($index_files)
if ($index_files != undef) {
validate_array($index_files)
}
if ($proxy != undef) {
validate_string($proxy)
}
Expand Down
68 changes: 52 additions & 16 deletions spec/defines/resource_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,35 +284,71 @@

describe 'vhost_location_alias template content' do
let :default_params do
{ location: 'location', vhost: 'vhost1', location_alias: 'value' }
{
location: 'location',
vhost: 'vhost1',
location_alias: 'value'
}
end

context "when location_alias is 'value'" do
context 'location_alias template with default params' do
let(:params) { default_params }
it { is_expected.to contain_concat__fragment('vhost1-500-' + Digest::MD5.hexdigest('location')) }
it 'sets alias' do
is_expected.to contain_concat__fragment('vhost1-500-' + Digest::MD5.hexdigest('location')).
with_content(%r{^[ ]+alias\s+value;})
with_content(%r{^\s+alias\s+value;})
end
end

context "when autoindex is 'on'" do
let(:params) { default_params.merge(autoindex: 'on') }
it { is_expected.to contain_concat__fragment('vhost1-500-' + Digest::MD5.hexdigest('location')) }
it 'sets autoindex' do
it "doesn't set try_files" do
is_expected.to contain_concat__fragment('vhost1-500-' + Digest::MD5.hexdigest('location')).
with_content(%r{^[ ]+autoindex\s+on;})
without_content(%r{^\s+try_files[^;]+;})
end
end

context 'when autoindex is not set' do
let(:params) { default_params }
it { is_expected.to contain_concat__fragment('vhost1-500-' + Digest::MD5.hexdigest('location')) }
it 'does not set autoindex' do
it "doesn't set autoindex" do
is_expected.to contain_concat__fragment('vhost1-500-' + Digest::MD5.hexdigest('location')).
without_content(%r{^[ ]+autoindex[^;]+;})
end
end

[
{
title: 'should set autoindex',
attr: 'autoindex',
value: 'on',
match: ' autoindex on;'
},
{
title: 'should set try_file(s)',
attr: 'try_files',
value: %w(name1 name2),
match: ' try_files name1 name2;'
},
{
title: 'should set index_file(s)',
attr: 'index_files',
value: %w(name1 name2),
match: ' index name1 name2;'
}
].each do |param|
context "when #{param[:attr]} is #{param[:value]}" do
let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) }

it { is_expected.to contain_concat__fragment('vhost1-500-' + Digest::MD5.hexdigest(params[:location].to_s)) }
it param[:title] do
fragment = 'vhost1-500-' + Digest::MD5.hexdigest(params[:location].to_s)
matches = Array(param[:match])

if matches.all? { |m| m.is_a? Regexp }
matches.each { |item| is_expected.to contain_concat__fragment(fragment).with_content(item) }
else
lines = catalogue.resource('concat::fragment', fragment).send(:parameters)[:content].split("\n")
expect(lines & matches).to eq(matches)
end

Array(param[:notmatch]).each do |item|
is_expected.to contain_concat__fragment('vhost1-500-' + Digest::MD5.hexdigest(params[:location].to_s)).without_content(item)
end
end
end
end
end

describe 'vhost_location_directory template content' do
Expand Down
6 changes: 6 additions & 0 deletions templates/vhost/locations/alias.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
<% if defined? @autoindex -%>
autoindex <%= @autoindex %>;
<% end -%>
<% if @index_files and @index_files.count > 0 -%>
index <% Array(@index_files).each do |i| %> <%= i %><% end %>;
<% end -%>
<% if @try_files -%>
try_files<% @try_files.each do |try| -%> <%= try %><% end -%>;
<% end -%>
2 changes: 1 addition & 1 deletion templates/vhost/locations/directory.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

autoindex <%= @autoindex %>;
<% end -%>
<% if @index_files.count > 0 -%>
<% if @index_files and @index_files.count > 0 -%>
index <% Array(@index_files).each do |i| %> <%= i %><% end %>;
<% end -%>
<% if @try_files -%>
Expand Down

0 comments on commit 1421b4c

Please sign in to comment.