From 73653a2471fb8ff859c967af807c2721438a2fcd Mon Sep 17 00:00:00 2001 From: Alberto Varela Date: Thu, 10 Nov 2016 04:08:25 +0100 Subject: [PATCH] Fix Bug: ensure => absent was not working on nginx::resource::location (#965) --- manifests/resource/location.pp | 49 +++++++++++++------------- spec/defines/resource_location_spec.rb | 25 +++++++++++++ 2 files changed, 50 insertions(+), 24 deletions(-) diff --git a/manifests/resource/location.pp b/manifests/resource/location.pp index 8ab2b49d7..421249bfa 100644 --- a/manifests/resource/location.pp +++ b/manifests/resource/location.pp @@ -435,33 +435,34 @@ } } - - ## Create stubs for vHost File Fragment Pattern - $location_md5 = md5($location) - if ($ssl_only != true) { - concat::fragment { "${vhost_sanitized}-${priority}-${location_md5}": - target => $config_file, - content => join([ - template('nginx/vhost/location_header.erb'), - $content_real, - template('nginx/vhost/location_footer.erb'), - ], ''), - order => $priority, + if $ensure == present { + ## Create stubs for vHost File Fragment Pattern + $location_md5 = md5($location) + if ($ssl_only != true) { + concat::fragment { "${vhost_sanitized}-${priority}-${location_md5}": + target => $config_file, + content => join([ + template('nginx/vhost/location_header.erb'), + $content_real, + template('nginx/vhost/location_footer.erb'), + ], ''), + order => $priority, + } } - } - ## Only create SSL Specific locations if $ssl is true. - if ($ssl == true or $ssl_only == true) { - $ssl_priority = $priority + 300 + ## Only create SSL Specific locations if $ssl is true. + if ($ssl == true or $ssl_only == true) { + $ssl_priority = $priority + 300 - concat::fragment { "${vhost_sanitized}-${ssl_priority}-${location_md5}-ssl": - target => $config_file, - content => join([ - template('nginx/vhost/location_header.erb'), - $content_real, - template('nginx/vhost/location_footer.erb'), - ], ''), - order => $ssl_priority, + concat::fragment { "${vhost_sanitized}-${ssl_priority}-${location_md5}-ssl": + target => $config_file, + content => join([ + template('nginx/vhost/location_header.erb'), + $content_real, + template('nginx/vhost/location_footer.erb'), + ], ''), + order => $ssl_priority, + } } } } diff --git a/spec/defines/resource_location_spec.rb b/spec/defines/resource_location_spec.rb index cdc364517..42253f1d6 100644 --- a/spec/defines/resource_location_spec.rb +++ b/spec/defines/resource_location_spec.rb @@ -927,6 +927,31 @@ it { is_expected.to contain_concat__fragment('www_rspec-vhost_com-500-' + Digest::MD5.hexdigest('www.rspec-location.com')).with_target('/etc/nginx/sites-available/www_rspec-vhost_com.conf') } it { is_expected.to contain_concat__fragment('www_rspec-vhost_com-800-' + Digest::MD5.hexdigest('www.rspec-location.com') + '-ssl').with_target('/etc/nginx/sites-available/www_rspec-vhost_com.conf') } end + + context 'when ensure => absent' do + let :params do + { + vhost: 'vhost1', + www_root: '/', + ensure: 'absent' + } + end + + it { is_expected.not_to contain_concat__fragment('vhost1-500-' + Digest::MD5.hexdigest('rspec-test')) } + end + + context 'when ensure => absent and ssl => true' do + let :params do + { + ssl: true, + vhost: 'vhost1', + www_root: '/', + ensure: 'absent' + } + end + + it { is_expected.not_to contain_concat__fragment('vhost1-800-' + Digest::MD5.hexdigest('rspec-test') + '-ssl') } + end end end end