Skip to content

Commit

Permalink
Merge pull request voxpupuli#1389 from tuxmea/stream_mapfiles
Browse files Browse the repository at this point in the history
Use correct stream mapfile location
  • Loading branch information
ekohl committed May 25, 2020
2 parents 5ac791e + 0cf0330 commit 26365b9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
12 changes: 9 additions & 3 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 @@ -77,14 +78,19 @@
Optional[String] $default = undef,
Enum['absent', 'present'] $ensure = 'present',
Array[String] $include_files = [],
Boolean $hostnames = false
Boolean $hostnames = false,
Enum['http', 'stream'] $context = '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 26365b9

Please sign in to comment.