Skip to content

Commit

Permalink
Use correct stream mapfile location
Browse files Browse the repository at this point in the history
Location for mapfiles differ if mapfile is loaded in http or stream context.
  • Loading branch information
Martin Alfke committed May 14, 2020
1 parent 845d06f commit 297fd86
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
10 changes: 8 additions & 2 deletions manifests/resource/map.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# [*hostnames*] - Indicates that source values can be hostnames with a
# prefix or suffix mask.
# [*include_files*] - An array of external files to include
# [*context'] - Specify if mapping is for http or stream context
#
# Actions:
#
Expand Down Expand Up @@ -78,13 +79,18 @@
Enum['absent', 'present'] $ensure = 'present',
Array[String] $include_files = [],
Boolean $hostnames = false
Enum['http', 'stream'] = 'http',
) {
if ! defined(Class['nginx']) {
fail('You must include the nginx base class before using any defined resources')
}

$root_group = $nginx::root_group
$conf_dir = "${nginx::conf_dir}/conf.d"

$conf_dir = $context ? {
'stream' => "${nginx::conf_dir}/conf.stream.d",
'http' => "${nginx::conf_dir}/conf.d",
}

$ensure_real = $ensure ? {
'absent' => absent,
Expand All @@ -97,7 +103,7 @@
mode => '0644',
}

file { "${nginx::conf_dir}/conf.d/${name}-map.conf":
file { "${conf_dir}/${name}-map.conf":
ensure => $ensure_real,
content => template('nginx/conf.d/map.erb'),
notify => Class['nginx::service'],
Expand Down
19 changes: 19 additions & 0 deletions spec/defines/resource_map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,25 @@
end
end

describe 'basic assumptions on stream mapfiles' do
let :params do
default_params.merge(
context: 'stream'
)
end

it { is_expected.to contain_file("/etc/nginx/conf.stream.d/#{title}-map.conf").that_requires('File[/etc/nginx/conf.stream.d]') }
it do
is_expected.to contain_file("/etc/nginx/conf.stream.d/#{title}-map.conf").with(
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
'ensure' => 'file',
'content' => %r{map \$uri \$#{title}}
)
end
end

describe 'map.conf template content' do
[
{
Expand Down

0 comments on commit 297fd86

Please sign in to comment.