Skip to content

Commit

Permalink
Merge pull request #1071 from cyon/feature/locations_defaults
Browse files Browse the repository at this point in the history
Add location defaults to init and server resource
  • Loading branch information
oranenj committed Apr 30, 2017
2 parents 73502ca + cbafefb commit 59c4eab
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
3 changes: 2 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
$geo_mappings = {},
$string_mappings = {},
$nginx_locations = {},
$nginx_locations_defaults = {},
$nginx_mailhosts = {},
$nginx_mailhosts_defaults = {},
$nginx_streamhosts = {},
Expand All @@ -169,7 +170,7 @@

create_resources('nginx::resource::upstream', $nginx_upstreams)
create_resources('nginx::resource::server', $nginx_servers, $nginx_servers_defaults)
create_resources('nginx::resource::location', $nginx_locations)
create_resources('nginx::resource::location', $nginx_locations, $nginx_locations_defaults)
create_resources('nginx::resource::mailhost', $nginx_mailhosts, $nginx_mailhosts_defaults)
create_resources('nginx::resource::streamhost', $nginx_streamhosts)
create_resources('nginx::resource::map', $string_mappings)
Expand Down
6 changes: 4 additions & 2 deletions manifests/resource/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
# [*maintenance_value*] - Value to return when maintenance is on. Default to return 503
# [*error_pages*] - Hash: setup errors pages, hash key is the http code and hash value the page
# [*locations*] - Hash of servers resources used by this server
# [*locations_defaults*] - Hash of location default settings
# Actions:
#
# Requires:
Expand Down Expand Up @@ -248,7 +249,8 @@
Boolean $maintenance = false,
String $maintenance_value = 'return 503',
$error_pages = undef,
Hash $locations = {}
Hash $locations = {},
Hash $locations_defaults = {}
) {

# Variables
Expand Down Expand Up @@ -450,5 +452,5 @@
ssl => $ssl,
ssl_only => $ssl_only,
www_root => $www_root,
})
} + $locations_defaults)
}
2 changes: 2 additions & 0 deletions spec/classes/nginx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
nginx_servers: { 'test2.local' => { 'www_root' => '/' } },
nginx_servers_defaults: { 'listen_options' => 'default_server' },
nginx_locations: { 'test2.local' => { 'server' => 'test2.local', 'www_root' => '/' } },
nginx_locations_defaults: { 'expires' => '@12h34m' },
nginx_mailhosts: { 'smtp.test2.local' => { 'auth_http' => 'server2.example/cgi-bin/auth', 'protocol' => 'smtp', 'listen_port' => 587 } },
nginx_mailhosts_defaults: { 'listen_options' => 'default_server_smtp' },
nginx_streamhosts: { 'streamhost1' => { 'proxy' => 'streamproxy' } }
Expand All @@ -29,6 +30,7 @@
it { is_expected.to contain_nginx__resource__server('test2.local') }
it { is_expected.to contain_nginx__resource__server('test2.local').with_listen_options('default_server') }
it { is_expected.to contain_nginx__resource__location('test2.local') }
it { is_expected.to contain_nginx__resource__location('test2.local').with_expires('@12h34m') }
it { is_expected.to contain_nginx__resource__mailhost('smtp.test2.local') }
it { is_expected.to contain_nginx__resource__mailhost('smtp.test2.local').with_listen_options('default_server_smtp') }
it { is_expected.to contain_nginx__resource__streamhost('streamhost1').with_proxy('streamproxy') }
Expand Down
76 changes: 76 additions & 0 deletions spec/defines/resource_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1242,5 +1242,81 @@
end
end
end

describe 'with locations' do
context 'simple location' do
let(:params) do
{
use_default_location: false,
locations: {
'one' => {
'location_custom_cfg' => {},
'location' => '/one',
'expires' => '@12h34m'
}
}
}
end
it { is_expected.to contain_nginx__resource__location('one') }
it { is_expected.to contain_nginx__resource__location('one').with_location('/one') }
it { is_expected.to contain_nginx__resource__location('one').with_expires('@12h34m') }
end

context 'multiple locations' do
let(:params) do
{
use_default_location: false,
locations: {
'one' => {
'location_custom_cfg' => {},
'location' => '/one',
'expires' => '@12h34m'
},
'two' => {
'location_custom_cfg' => {},
'location' => '= /two',
'expires' => '@23h45m'
}
}
}
end
it { is_expected.to contain_nginx__resource__location('one') }
it { is_expected.to contain_nginx__resource__location('one').with_location('/one') }
it { is_expected.to contain_nginx__resource__location('one').with_expires('@12h34m') }
it { is_expected.to contain_nginx__resource__location('two') }
it { is_expected.to contain_nginx__resource__location('two').with_location('= /two') }
it { is_expected.to contain_nginx__resource__location('two').with_expires('@23h45m') }
end

context 'with locations default' do
let(:params) do
{
www_root: '/toplevel',
locations_defaults: {
'www_root' => '/overwrite',
'expires' => '@12h34m'
},
locations: {
'one' => {
'location_custom_cfg' => {},
'location' => '/one'
},
'two' => {
'location_custom_cfg' => {},
'location' => '= /two'
}
}
}
end
it { is_expected.to contain_nginx__resource__location('one') }
it { is_expected.to contain_nginx__resource__location('one').with_location('/one') }
it { is_expected.to contain_nginx__resource__location('one').with_www_root('/overwrite') }
it { is_expected.to contain_nginx__resource__location('one').with_expires('@12h34m') }
it { is_expected.to contain_nginx__resource__location('two') }
it { is_expected.to contain_nginx__resource__location('two').with_location('= /two') }
it { is_expected.to contain_nginx__resource__location('two').with_www_root('/overwrite') }
it { is_expected.to contain_nginx__resource__location('two').with_expires('@12h34m') }
end
end
end
end

0 comments on commit 59c4eab

Please sign in to comment.