diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 048d2b55d..8b466cfb9 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -124,7 +124,7 @@ If you have Ruby 2.x or want a specific version of Puppet, you must set an environment variable such as: ```sh -export PUPPET_VERSION="~> 5.5.6" +export PUPPET_GEM_VERSION="~> 6.1.0" ``` You can install all needed gems for spec tests into the modules directory by @@ -232,17 +232,16 @@ simple tests against it after applying the module. You can run this with: ```sh -BEAKER_setfile=debian10-x64 bundle exec rake beaker +BEAKER_setfile=debian11-64 bundle exec rake beaker ``` You can replace the string `debian10` with any common operating system. The following strings are known to work: -* ubuntu1604 * ubuntu1804 * ubuntu2004 -* debian9 * debian10 +* debian11 * centos7 * centos8 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f5745254..8a0779116 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,84 +7,12 @@ name: CI on: pull_request concurrency: - group: ${{ github.head_ref }} + group: ${{ github.ref_name }} cancel-in-progress: true jobs: - setup_matrix: - name: 'Setup Test Matrix' - runs-on: ubuntu-latest - timeout-minutes: 60 - outputs: - puppet_unit_test_matrix: ${{ steps.get-outputs.outputs.puppet_unit_test_matrix }} - github_action_test_matrix: ${{ steps.get-outputs.outputs.github_action_test_matrix }} - env: - BUNDLE_WITHOUT: development:system_tests:release - steps: - - uses: actions/checkout@v2 - - name: Setup ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.0' - bundler-cache: true - - name: Run static validations - run: bundle exec rake validate lint check - - name: Run rake rubocop - run: bundle exec rake rubocop - - name: Setup Test Matrix - id: get-outputs - run: bundle exec metadata2gha --use-fqdn --pidfile-workaround false - - unit: - needs: setup_matrix - runs-on: ubuntu-latest - timeout-minutes: 60 - strategy: - fail-fast: false - matrix: - include: ${{fromJson(needs.setup_matrix.outputs.puppet_unit_test_matrix)}} - env: - BUNDLE_WITHOUT: development:system_tests:release - PUPPET_VERSION: "~> ${{ matrix.puppet }}.0" - name: Puppet ${{ matrix.puppet }} (Ruby ${{ matrix.ruby }}) - steps: - - uses: actions/checkout@v2 - - name: Setup ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true - - name: Run tests - run: bundle exec rake parallel_spec - - acceptance: - needs: setup_matrix - runs-on: ubuntu-latest - env: - BUNDLE_WITHOUT: development:test:release - strategy: - fail-fast: false - matrix: - include: ${{fromJson(needs.setup_matrix.outputs.github_action_test_matrix)}} - name: ${{ matrix.puppet.name }} - ${{ matrix.setfile.name }} - steps: - - uses: actions/checkout@v2 - - name: Setup ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.0' - bundler-cache: true - - name: Run tests - run: bundle exec rake beaker - env: - BEAKER_PUPPET_COLLECTION: ${{ matrix.puppet.collection }} - BEAKER_setfile: ${{ matrix.setfile.value }} - - tests: - needs: - - unit - - acceptance - runs-on: ubuntu-latest - name: Test suite - steps: - - run: echo Test suite completed + puppet: + name: Puppet + uses: voxpupuli/gha-puppet/.github/workflows/beaker.yml@v1 + with: + pidfile_workaround: 'false' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 664ba6946..15f172134 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,26 +9,14 @@ on: tags: - '*' -env: - BUNDLE_WITHOUT: development:test:system_tests - jobs: - deploy: - name: 'deploy to forge' - runs-on: ubuntu-latest - if: github.repository_owner == 'voxpupuli' - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - name: Setup Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: '2.7' - bundler-cache: true - - name: Build and Deploy - env: - # Configure secrets here: - # https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets - BLACKSMITH_FORGE_USERNAME: '${{ secrets.PUPPET_FORGE_USERNAME }}' - BLACKSMITH_FORGE_API_KEY: '${{ secrets.PUPPET_FORGE_API_KEY }}' - run: bundle exec rake module:push + release: + name: Release + uses: voxpupuli/gha-puppet/.github/workflows/release.yml@v1 + with: + allowed_owner: 'voxpupuli' + secrets: + # Configure secrets here: + # https://docs.github.com/en/actions/security-guides/encrypted-secrets + username: ${{ secrets.PUPPET_FORGE_USERNAME }} + api_key: ${{ secrets.PUPPET_FORGE_API_KEY }} diff --git a/.msync.yml b/.msync.yml index 43966c2f5..968a93678 100644 --- a/.msync.yml +++ b/.msync.yml @@ -2,4 +2,4 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -modulesync_config_version: '4.2.0' +modulesync_config_version: '5.2.0' diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 000000000..dd8272c7b --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1,3 @@ +--fail-on-warnings +--no-parameter_documentation-check +--no-parameter_types-check diff --git a/.rubocop.yml b/.rubocop.yml index 53ac18982..ea22bff86 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,6 @@ --- +inherit_from: .rubocop_todo.yml + # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 000000000..2218a097f --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,25 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2022-03-21 13:44:28 UTC using RuboCop version 1.22.3. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 7 +# Configuration parameters: AllowSubject. +RSpec/MultipleMemoizedHelpers: + Max: 7 + +# Offense count: 8 +RSpec/RepeatedExampleGroupBody: + Exclude: + - 'spec/acceptance/nginx_mail_spec.rb' + - 'spec/acceptance/nginx_server_spec.rb' + - 'spec/defines/resource_mailhost_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/SelectByRegexp: + Exclude: + - 'spec/defines/resource_location_spec.rb' diff --git a/Dockerfile b/Dockerfile index e3cf307f1..8dd82d636 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ WORKDIR /opt/puppet # https://github.com/puppetlabs/puppet/blob/06ad255754a38f22fb3a22c7c4f1e2ce453d01cb/lib/puppet/provider/service/runit.rb#L39 RUN mkdir -p /etc/sv -ARG PUPPET_VERSION="~> 6.0" +ARG PUPPET_GEM_VERSION="~> 6.0" ARG PARALLEL_TEST_PROCESSORS=4 # Cache gems diff --git a/Gemfile b/Gemfile index a39114ce3..225c39694 100644 --- a/Gemfile +++ b/Gemfile @@ -1,10 +1,10 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -source ENV['GEM_SOURCE'] || "https://rubygems.org" +source ENV['GEM_SOURCE'] || 'https://rubygems.org' group :test do - gem 'voxpupuli-test', '~> 2.5', :require => false + gem 'voxpupuli-test', '~> 5.0', :require => false gem 'coveralls', :require => false gem 'simplecov-console', :require => false gem 'puppet_metadata', '~> 1.0', :require => false @@ -21,14 +21,14 @@ end group :release do gem 'github_changelog_generator', '>= 1.16.1', :require => false if RUBY_VERSION >= '2.5' - gem 'voxpupuli-release', '>= 1.0.2', :require => false + gem 'voxpupuli-release', '>= 1.2.0', :require => false gem 'puppet-strings', '>= 2.2', :require => false end gem 'rake', :require => false gem 'facter', ENV['FACTER_GEM_VERSION'], :require => false, :groups => [:test] -puppetversion = ENV['PUPPET_VERSION'] || '>= 6.0' +puppetversion = ENV['PUPPET_GEM_VERSION'] || '>= 6.0' gem 'puppet', puppetversion, :require => false, :groups => [:test] # vim: syntax=ruby diff --git a/Rakefile b/Rakefile index 80b799d63..f92f05164 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -# Attempt to load voxupuli-test (which pulls in puppetlabs_spec_helper), +# Attempt to load voxpupuli-test (which pulls in puppetlabs_spec_helper), # otherwise attempt to load it directly. begin require 'voxpupuli/test/rake' diff --git a/lib/facter/nginx_version.rb b/lib/facter/nginx_version.rb index 6509d774b..8eb60591f 100644 --- a/lib/facter/nginx_version.rb +++ b/lib/facter/nginx_version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Facter.add(:nginx_version) do confine { Facter.value(:kernel) != 'windows' } confine { Facter.value(:operatingsystem) != 'nexus' } @@ -5,7 +7,7 @@ if Facter::Util::Resolution.which('nginx') || Facter::Util::Resolution.which('openresty') nginx_version_command = Facter::Util::Resolution.which('nginx') ? 'nginx -v 2>&1' : 'openresty -v 2>&1' nginx_version = Facter::Util::Resolution.exec(nginx_version_command) - %r{nginx version: (nginx|openresty)\/([\w\.]+)}.match(nginx_version)[2] + %r{nginx version: (nginx|openresty)/([\w.]+)}.match(nginx_version)[2] end end end diff --git a/manifests/package/redhat.pp b/manifests/package/redhat.pp index e415bdd69..b1816bbd0 100644 --- a/manifests/package/redhat.pp +++ b/manifests/package/redhat.pp @@ -19,17 +19,24 @@ default => 'rhel' } + $want_module_hotfixes = if versioncmp(fact('os.release.full'), '8.0') >= 0 { + '1' + } else { + 'absent' + } + if $manage_repo { case $package_source { 'nginx', 'nginx-stable': { yumrepo { 'nginx-release': - baseurl => "https://nginx.org/packages/${_os}/${facts['os']['release']['major']}/\$basearch/", - descr => 'nginx repo', - enabled => '1', - gpgcheck => '1', - priority => '1', - gpgkey => 'https://nginx.org/keys/nginx_signing.key', - before => Package['nginx'], + baseurl => "https://nginx.org/packages/${_os}/${facts['os']['release']['major']}/\$basearch/", + descr => 'nginx repo', + enabled => '1', + gpgcheck => '1', + priority => '1', + gpgkey => 'https://nginx.org/keys/nginx_signing.key', + before => Package['nginx'], + module_hotfixes => $want_module_hotfixes, } if $purge_passenger_repo { @@ -41,13 +48,14 @@ } 'nginx-mainline': { yumrepo { 'nginx-release': - baseurl => "https://nginx.org/packages/mainline/${_os}/${facts['os']['release']['major']}/\$basearch/", - descr => 'nginx repo', - enabled => '1', - gpgcheck => '1', - priority => '1', - gpgkey => 'https://nginx.org/keys/nginx_signing.key', - before => Package['nginx'], + baseurl => "https://nginx.org/packages/mainline/${_os}/${facts['os']['release']['major']}/\$basearch/", + descr => 'nginx repo', + enabled => '1', + gpgcheck => '1', + priority => '1', + gpgkey => 'https://nginx.org/keys/nginx_signing.key', + before => Package['nginx'], + module_hotfixes => $want_module_hotfixes, } if $purge_passenger_repo { @@ -58,21 +66,22 @@ } } 'passenger': { - if ($facts['os']['name'] in ['RedHat', 'CentOS', 'VirtuozzoLinux']) and ($facts['os']['release']['major'] in ['6', '7', '8']) { + if ($facts['os']['name'] in ['RedHat', 'CentOS', 'VirtuozzoLinux']) and ($facts['os']['release']['major'] in ['6', '7']) { # 2019-11: Passenger changed their gpg key from: `https://packagecloud.io/phusion/passenger/gpgkey` # to: `https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt` # Find the latest key by opening: https://oss-binaries.phusionpassenger.com/yum/definitions/el-passenger.repo # Also note: Since 6.0.5 there are no nginx packages in the phusion EL7 repository, and nginx packages are expected to come from epel instead yumrepo { 'passenger': - baseurl => "https://oss-binaries.phusionpassenger.com/yum/passenger/el/${facts['os']['release']['major']}/\$basearch", - descr => 'passenger repo', - enabled => '1', - gpgcheck => '0', - repo_gpgcheck => '1', - priority => '1', - gpgkey => 'https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt', - before => Package['nginx'], + baseurl => "https://oss-binaries.phusionpassenger.com/yum/passenger/el/${facts['os']['release']['major']}/\$basearch", + descr => 'passenger repo', + enabled => '1', + gpgcheck => '0', + repo_gpgcheck => '1', + priority => '1', + gpgkey => 'https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt', + before => Package['nginx'], + module_hotfixes => $want_module_hotfixes, } yumrepo { 'nginx-release': diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index b5a269b51..d638944bb 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -1,11 +1,17 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'nginx class:' do + test_passenger = true + case fact('osfamily') when 'RedHat' pkg_cmd = 'yum info nginx | grep "^From repo"' pkg_remove_cmd = 'yum -y remove nginx nginx-filesystem passenger' pkg_match = case fact('operatingsystemmajrelease') + when '8' + test_passenger = false when '7' # https://blog.phusion.nl/2020/05/29/passenger-6-0-5/ %r{epel} else @@ -22,6 +28,8 @@ else %r{Phusion} end + else + test_passenger = false end context 'default parameters' do @@ -42,7 +50,7 @@ end end - context 'nginx with package_source passenger', if: pkg_cmd do + context 'nginx with package_source passenger', if: test_passenger do it 'runs successfully' do shell(pkg_remove_cmd) pp = <<-EOS @@ -57,6 +65,7 @@ class { 'nginx': describe package('nginx') do it { is_expected.to be_installed } + it 'comes from the expected source' do pkg_output = shell(pkg_cmd) expect(pkg_output.stdout).to match pkg_match @@ -73,7 +82,7 @@ class { 'nginx': end end - context 'reset to default parameters', if: pkg_cmd do + context 'reset to default parameters', if: pkg_remove_cmd do it 'runs successfully' do shell(pkg_remove_cmd) pp = "class { 'nginx': }" diff --git a/spec/acceptance/init_spec.rb b/spec/acceptance/init_spec.rb index 64ada1ca7..6b676f327 100644 --- a/spec/acceptance/init_spec.rb +++ b/spec/acceptance/init_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'nginx class' do diff --git a/spec/acceptance/nginx_location_spec.rb b/spec/acceptance/nginx_location_spec.rb index f01e3ff22..377854b74 100644 --- a/spec/acceptance/nginx_location_spec.rb +++ b/spec/acceptance/nginx_location_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'nginx::resource::location define:' do @@ -45,6 +47,7 @@ class { 'nginx': } it { is_expected.to contain ' location /.well-known/acme-challenge/ {' } it { is_expected.to contain ' root /var/www/letsencrypt;' } end + describe file('/etc/nginx/sites-available/stage.puppetlabs.com.conf') do it { is_expected.to be_file } it { is_expected.to contain '# MANAGED BY PUPPET' } diff --git a/spec/acceptance/nginx_mail_spec.rb b/spec/acceptance/nginx_mail_spec.rb index cbca9675f..820faabc5 100644 --- a/spec/acceptance/nginx_mail_spec.rb +++ b/spec/acceptance/nginx_mail_spec.rb @@ -1,86 +1,120 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'nginx::resource::mailhost define:' do - it 'runs successfully' do - pp = " - if fact('os.family') == 'RedHat' { - package { 'nginx-mod-mail': - ensure => installed, - } - } + has_recent_mail_module = true - class { 'nginx': - mail => true, - dynamic_modules => fact('os.family') ? { - 'RedHat' => ['/usr/lib64/nginx/modules/ngx_mail_module.so'], - default => [], - } + if fact('os.family') == 'RedHat' && fact('os.release.major') == '8' + # EPEL had recent nginx-mod-mail package for CentOS 7 but not CentOS 8 + # Stream. The base packages use an older version of nginx that does not + # work with the acceptance test configuration. + has_recent_mail_module = false + end + + it 'remove leftovers from previous tests', if: fact('os.family') == 'RedHat' do + shell('yum -y remove nginx nginx-filesystem passenger') + # nginx-mod-mail is not available for all versions of nginx, the one + # installed might be incompatible with the version of nginx-mod-mail we are + # about to install so clean everything. + pp = " + yumrepo { 'nginx-release': + ensure => absent, } - nginx::resource::mailhost { 'domain1.example': - ensure => present, - auth_http => 'localhost/cgi-bin/auth', - protocol => 'smtp', - listen_port => 587, - ssl => true, - ssl_port => 465, - ssl_cert => '/etc/pki/tls/certs/blah.cert', - ssl_key => '/etc/pki/tls/private/blah.key', - xclient => 'off', + yumrepo { 'passenger': + ensure => absent, } " - apply_manifest(pp, catch_failures: true) end - describe file('/etc/nginx/conf.mail.d/domain1.example.conf') do - it { is_expected.to be_file } - it { is_expected.to contain 'auth_http localhost/cgi-bin/auth;' } - it { is_expected.to contain 'listen *:465 ssl;' } - end - - describe port(587) do - it { is_expected.to be_listening } - end - - describe port(465) do - it { is_expected.to be_listening } - end - - context 'when configured for nginx 1.14' do + context 'actualy test the mail module', if: has_recent_mail_module do it 'runs successfully' do pp = " - if fact('os.family') == 'RedHat' { - package { 'nginx-mod-mail': - ensure => installed, + if fact('os.family') == 'RedHat' { + package { 'nginx-mod-mail': + ensure => installed, + } } - } - class { 'nginx': - mail => true, - nginx_version => '1.14.0', - dynamic_modules => fact('os.family') ? { - 'RedHat' => ['/usr/lib64/nginx/modules/ngx_mail_module.so'], - default => [], + class { 'nginx': + mail => true, + dynamic_modules => fact('os.family') ? { + 'RedHat' => ['/usr/lib64/nginx/modules/ngx_mail_module.so'], + default => [], + } + } + nginx::resource::mailhost { 'domain1.example': + ensure => present, + auth_http => 'localhost/cgi-bin/auth', + protocol => 'smtp', + listen_port => 587, + ssl => true, + ssl_port => 465, + ssl_cert => '/etc/pki/tls/certs/blah.cert', + ssl_key => '/etc/pki/tls/private/blah.key', + xclient => 'off', } - } - nginx::resource::mailhost { 'domain1.example': - ensure => present, - auth_http => 'localhost/cgi-bin/auth', - protocol => 'smtp', - listen_port => 587, - ssl => true, - ssl_port => 465, - ssl_cert => '/etc/pki/tls/certs/blah.cert', - ssl_key => '/etc/pki/tls/private/blah.key', - xclient => 'off', - } " apply_manifest(pp, catch_failures: true) + # The module produce different config when nginx is installed and when it + # is not installed prior to getting facts, so we need to re-apply the + # catalog. + apply_manifest(pp, catch_failures: true) end + describe file('/etc/nginx/conf.mail.d/domain1.example.conf') do - it 'does\'t contain `ssl` on `listen` line' do - is_expected.to contain 'listen *:465;' + it { is_expected.to be_file } + it { is_expected.to contain 'auth_http localhost/cgi-bin/auth;' } + it { is_expected.to contain 'listen *:465 ssl;' } + end + + describe port(587) do + it { is_expected.to be_listening } + end + + describe port(465) do + it { is_expected.to be_listening } + end + + context 'when configured for nginx 1.14' do + it 'runs successfully' do + pp = " + if fact('os.family') == 'RedHat' { + package { 'nginx-mod-mail': + ensure => installed, + } + } + + class { 'nginx': + mail => true, + nginx_version => '1.14.0', + dynamic_modules => fact('os.family') ? { + 'RedHat' => ['/usr/lib64/nginx/modules/ngx_mail_module.so'], + default => [], + } + } + nginx::resource::mailhost { 'domain1.example': + ensure => present, + auth_http => 'localhost/cgi-bin/auth', + protocol => 'smtp', + listen_port => 587, + ssl => true, + ssl_port => 465, + ssl_cert => '/etc/pki/tls/certs/blah.cert', + ssl_key => '/etc/pki/tls/private/blah.key', + xclient => 'off', + } + " + + apply_manifest(pp, catch_failures: true) + end + + describe file('/etc/nginx/conf.mail.d/domain1.example.conf') do + it 'does\'t contain `ssl` on `listen` line' do + is_expected.to contain 'listen *:465;' + end end end end diff --git a/spec/acceptance/nginx_proxy_spec.rb b/spec/acceptance/nginx_proxy_spec.rb index 9a80269a3..447ecbfd2 100644 --- a/spec/acceptance/nginx_proxy_spec.rb +++ b/spec/acceptance/nginx_proxy_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'nginx::resource::upstream define:' do diff --git a/spec/acceptance/nginx_server_spec.rb b/spec/acceptance/nginx_server_spec.rb old mode 100755 new mode 100644 index d1d9c332f..6bbc85c87 --- a/spec/acceptance/nginx_server_spec.rb +++ b/spec/acceptance/nginx_server_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'nginx::resource::server define:' do @@ -49,6 +51,10 @@ class { 'nginx': } end context 'should run successfully with ssl' do + it 'remove leftovers from previous tests', if: fact('os.family') == 'RedHat' do + shell('yum -y remove nginx nginx-filesystem passenger') + end + it 'configures a nginx SSL server' do pp = " class { 'nginx': } @@ -69,7 +75,6 @@ class { 'nginx': } describe file('/etc/nginx/sites-available/www.puppetlabs.com.conf') do it { is_expected.to be_file } - it { is_expected.not_to contain 'ssl on;' } # As of nginx 1.15 (1.16 stable), this will not be set. it { is_expected.to contain 'listen *:443 ssl;' } it { is_expected.not_to contain 'shared:SSL:10m;' } end diff --git a/spec/acceptance/nginx_upstream_spec.rb b/spec/acceptance/nginx_upstream_spec.rb index 4fec3a103..4a4bb1bf2 100644 --- a/spec/acceptance/nginx_upstream_spec.rb +++ b/spec/acceptance/nginx_upstream_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'nginx::resource::upstream define:' do @@ -88,6 +90,7 @@ class { 'nginx': } it { is_expected.to contain ' zone production 64k;' } it { is_expected.to contain ' keepalive 16;' } end + describe file('/etc/nginx/sites-available/www.puppetlabs.com.conf') do it { is_expected.to be_file } it { is_expected.to contain '# MANAGED BY PUPPET' } @@ -102,6 +105,7 @@ class { 'nginx': } it { is_expected.to contain ' server unix:/var/run/socket_02.sock max_conns=20 max_fails=20 fail_timeout=20s;' } it { is_expected.to contain ' zone socket 64k;' } end + describe file('/etc/nginx/sites-available/socket.puppetlabs.com.conf') do it { is_expected.to be_file } it { is_expected.to contain '# MANAGED BY PUPPET' } diff --git a/spec/classes/nginx_spec.rb b/spec/classes/nginx_spec.rb index e98e6d953..5e8f910b4 100644 --- a/spec/classes/nginx_spec.rb +++ b/spec/classes/nginx_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'nginx' do @@ -37,10 +39,13 @@ end context 'nginx::package' do + it { is_expected.to compile.with_all_deps } + case facts[:osfamily] when 'RedHat' context 'using defaults' do it { is_expected.to contain_package('nginx') } + it do is_expected.to contain_yumrepo('nginx-release').with( 'baseurl' => "https://nginx.org/packages/#{%w[CentOS VirtuozzoLinux].include?(facts[:operatingsystem]) ? 'centos' : 'rhel'}/#{facts[:operatingsystemmajrelease]}/$basearch/", @@ -51,11 +56,13 @@ 'gpgkey' => 'https://nginx.org/keys/nginx_signing.key' ) end + it do is_expected.to contain_yumrepo('passenger').with( 'ensure' => 'absent' ) end + it { is_expected.to contain_yumrepo('nginx-release').that_comes_before('Package[nginx]') } it { is_expected.to contain_yumrepo('passenger').that_comes_before('Package[nginx]') } end @@ -64,6 +71,7 @@ let(:params) { { purge_passenger_repo: false } } it { is_expected.to contain_package('nginx') } + it do is_expected.to contain_yumrepo('nginx-release').with( 'baseurl' => "https://nginx.org/packages/#{%w[CentOS VirtuozzoLinux].include?(facts[:operatingsystem]) ? 'centos' : 'rhel'}/#{facts[:operatingsystemmajrelease]}/$basearch/", @@ -86,16 +94,18 @@ 'baseurl' => "https://nginx.org/packages/mainline/#{%w[CentOS VirtuozzoLinux].include?(facts[:operatingsystem]) ? 'centos' : 'rhel'}/#{facts[:operatingsystemmajrelease]}/$basearch/" ) end + it do is_expected.to contain_yumrepo('passenger').with( 'ensure' => 'absent' ) end + it { is_expected.to contain_yumrepo('nginx-release').that_comes_before('Package[nginx]') } it { is_expected.to contain_yumrepo('passenger').that_comes_before('Package[nginx]') } end - context 'package_source => passenger' do + context 'package_source => passenger', unless: facts[:operatingsystemmajrelease] == '8' do let(:params) { { package_source: 'passenger' } } it do @@ -106,17 +116,19 @@ 'gpgkey' => 'https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt' ) end + it do is_expected.to contain_yumrepo('nginx-release').with( 'ensure' => 'absent' ) end + it { is_expected.to contain_yumrepo('passenger').that_comes_before('Package[nginx]') } it { is_expected.to contain_yumrepo('nginx-release').that_comes_before('Package[nginx]') } it { is_expected.to contain_package('passenger').with('ensure' => 'present') } end - describe 'installs the requested passenger package version' do + describe 'installs the requested passenger package version', unless: facts[:operatingsystemmajrelease] == '8' do let(:params) { { package_source: 'passenger', passenger_package_ensure: '4.1.0-1.el9' } } it 'installs specified version exactly' do @@ -143,11 +155,12 @@ context 'using defaults' do it { is_expected.to contain_package('nginx') } it { is_expected.not_to contain_package('passenger') } + it do is_expected.to contain_apt__source('nginx').with( - 'location' => "https://nginx.org/packages/#{facts[:operatingsystem].downcase}", - 'repos' => 'nginx', - 'key' => { 'id' => '573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62' } + 'location' => "https://nginx.org/packages/#{facts[:operatingsystem].downcase}", + 'repos' => 'nginx', + 'key' => { 'id' => '573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62' } ) end end @@ -176,17 +189,18 @@ let(:params) { { package_source: 'passenger' } } it { is_expected.to contain_package('nginx') } - if facts[:lsbdistid] == 'Debian' && %w[9 10].include?(facts.dig(:os, 'release', 'major')) || - facts[:lsbdistid] == 'Ubuntu' && %w[bionic focal].include?(facts[:lsbdistcodename]) + + if (facts[:lsbdistid] == 'Debian' && %w[9 10].include?(facts.dig(:os, 'release', 'major'))) || + (facts[:lsbdistid] == 'Ubuntu' && %w[bionic focal].include?(facts[:lsbdistcodename])) it { is_expected.to contain_package('libnginx-mod-http-passenger') } else it { is_expected.to contain_package('passenger') } end it do is_expected.to contain_apt__source('nginx').with( - 'location' => 'https://oss-binaries.phusionpassenger.com/apt/passenger', - 'repos' => 'main', - 'key' => { 'id' => '16378A33A6EF16762922526E561F9B9CAC40B2F7' } + 'location' => 'https://oss-binaries.phusionpassenger.com/apt/passenger', + 'repos' => 'main', + 'key' => { 'id' => '16378A33A6EF16762922526E561F9B9CAC40B2F7' } ) end end @@ -274,6 +288,7 @@ mode: '0644' ) end + it do is_expected.to contain_file('/etc/nginx/conf.d').only_with( path: '/etc/nginx/conf.d', @@ -283,6 +298,7 @@ mode: '0644' ) end + it do is_expected.to contain_file('/etc/nginx/conf.stream.d').only_with( path: '/etc/nginx/conf.stream.d', @@ -292,6 +308,7 @@ mode: '0644' ) end + it do is_expected.to contain_file('/etc/nginx/conf.mail.d').only_with( path: '/etc/nginx/conf.mail.d', @@ -301,6 +318,7 @@ mode: '0644' ) end + it do is_expected.to contain_file('/etc/nginx/nginx.conf').with( ensure: 'file', @@ -309,6 +327,7 @@ mode: '0644' ) end + it do is_expected.to contain_file('/etc/nginx/mime.types').with( ensure: 'file', @@ -317,6 +336,7 @@ mode: '0644' ) end + it do is_expected.to contain_file('/tmp/nginx.d').with( ensure: 'absent', @@ -324,6 +344,7 @@ recurse: true ) end + it do is_expected.to contain_file('/tmp/nginx.mail.d').with( ensure: 'absent', @@ -331,6 +352,7 @@ recurse: true ) end + context 'manage_log_dir => false' do let(:params) { { manage_log_dir: false } } @@ -340,9 +362,11 @@ ) end end + case facts[:osfamily] when 'RedHat' it { is_expected.to contain_file('/etc/nginx/nginx.conf').with_content %r{^user nginx;} } + it do is_expected.to contain_file('/var/log/nginx').with( ensure: 'directory', @@ -354,6 +378,7 @@ end when 'Debian' it { is_expected.to contain_file('/etc/nginx/nginx.conf').with_content %r{^user www-data;} } + it do is_expected.to contain_file('/var/log/nginx').with( ensure: 'directory', @@ -1077,6 +1102,7 @@ let(:params) { { param[:attr].to_sym => param[:value] } } it { is_expected.to contain_file('/etc/nginx/nginx.conf').with_mode('0644') } + it param[:title] do matches = Array(param[:match]) @@ -1090,7 +1116,7 @@ # if we have a _path attribute make sure we create the path if param[:attr].end_with?('_path') if param[:value].is_a?(Hash) - param[:value].keys.each do |path| + param[:value].each_key do |path| is_expected.to contain_file(path).with_ensure('directory') end else @@ -1121,7 +1147,7 @@ it { is_expected.to contain_file('/etc/nginx/mime.types').with_content(%r{audio/mpeg mp3;}) } end - context 'when mime.types is "[\'custom/file customfile\']" and mime.types.preserve.defaults is true' do + context 'when mime.types is "[custom/file customfile]" and mime.types.preserve.defaults is true' do let(:params) do { mime_types: { 'custom/file' => 'customfile' }, @@ -1133,7 +1159,7 @@ it { is_expected.to contain_file('/etc/nginx/mime.types').with_content(%r{custom/file customfile;}) } end - context 'when dynamic_modules is "[\'ngx_http_geoip_module\']" ' do + context 'when dynamic_modules is "[ngx_http_geoip_module]"' do let(:params) do { dynamic_modules: ['ngx_http_geoip_module'] @@ -1143,7 +1169,7 @@ it { is_expected.to contain_file('/etc/nginx/nginx.conf').with_content(%r{load_module "modules/ngx_http_geoip_module.so";}) } end - context 'when dynamic_modules is "[\'/path/to/module/ngx_http_geoip_module.so\']" ' do + context 'when dynamic_modules is "[/path/to/module/ngx_http_geoip_module.so]"' do let(:params) do { dynamic_modules: ['/path/to/module/ngx_http_geoip_module.so'] @@ -1244,6 +1270,7 @@ recurse: true ) end + it do is_expected.to contain_file('/etc/nginx/sites-enabled').with( purge: true, @@ -1267,6 +1294,7 @@ recurse: true ) end + it do is_expected.to contain_file('/etc/nginx/conf.stream.d').with( purge: true, @@ -1290,6 +1318,7 @@ ] ) end + it do is_expected.to contain_file('/etc/nginx/conf.stream.d').without( %w[ @@ -1311,6 +1340,7 @@ ] ) end + it do is_expected.to contain_file('/etc/nginx/sites-enabled').without( %w[ @@ -1320,6 +1350,7 @@ ] ) end + it do is_expected.to contain_file('/var/log/nginx').without( %w[ @@ -1329,6 +1360,7 @@ ] ) end + it do is_expected.to contain_file('/etc/nginx/streams-available').without( %w[ @@ -1338,6 +1370,7 @@ ] ) end + it do is_expected.to contain_file('/etc/nginx/streams-enabled').without( %w[ @@ -1365,11 +1398,13 @@ let(:params) { { log_dir: '/foo/bar' } } it { is_expected.to contain_file('/foo/bar').with(ensure: 'directory') } + it do is_expected.to contain_file('/etc/nginx/nginx.conf').with_content( %r{access_log /foo/bar/access.log;} ) end + it do is_expected.to contain_file('/etc/nginx/nginx.conf').with_content( %r{error_log /foo/bar/error.log error;} @@ -1391,31 +1426,37 @@ %r{ gzip on;} ) end + it do is_expected.to contain_file('/etc/nginx/nginx.conf').with_content( %r{ gzip_comp_level 1;} ) end + it do is_expected.to contain_file('/etc/nginx/nginx.conf').with_content( %r{ gzip_disable msie6;} ) end + it do is_expected.to contain_file('/etc/nginx/nginx.conf').with_content( %r{ gzip_min_length 20;} ) end + it do is_expected.to contain_file('/etc/nginx/nginx.conf').with_content( %r{ gzip_http_version 1.1;} ) end + it do is_expected.to contain_file('/etc/nginx/nginx.conf').with_content( %r{ gzip_vary off;} ) end + it do is_expected.to contain_file('/etc/nginx/nginx.conf').with_content( %r{ gzip_proxied off;} diff --git a/spec/defines/resource_geo_spec.rb b/spec/defines/resource_geo_spec.rb index 861e2079d..59f527ff7 100644 --- a/spec/defines/resource_geo_spec.rb +++ b/spec/defines/resource_geo_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'nginx::resource::geo' do @@ -33,9 +35,10 @@ let(:params) { default_params } it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-geo.conf").that_requires('File[/etc/nginx/conf.d]') } + it do is_expected.to contain_file("/etc/nginx/conf.d/#{title}-geo.conf").with( - 'owner' => 'root', + 'owner' => 'root', 'group' => 'root', 'mode' => '0644', 'ensure' => 'file', @@ -104,6 +107,7 @@ let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) } it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-geo.conf").with_mode('0644') } + it param[:title] do verify_contents(catalogue, "/etc/nginx/conf.d/#{title}-geo.conf", Array(param[:match])) Array(param[:notmatch]).each do |item| diff --git a/spec/defines/resource_location_spec.rb b/spec/defines/resource_location_spec.rb index 369856e9e..8979472ac 100644 --- a/spec/defines/resource_location_spec.rb +++ b/spec/defines/resource_location_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'digest/md5' @@ -38,15 +40,16 @@ let(:params) { { location: 'my_location', proxy: 'proxy_value', server: 'server1' } } it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)) } - it { is_expected.not_to contain_concat__fragment('server2-500-' + Digest::MD5.hexdigest(params[:location].to_s)) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}") } + it { is_expected.not_to contain_concat__fragment("server2-500-#{Digest::MD5.hexdigest(params[:location].to_s)}") } end + context 'when we have one location and two server' do let(:params) { { location: 'my_location', proxy: 'proxy_value', server: %w[server1 server2] } } it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)) } - it { is_expected.to contain_concat__fragment('server2-500-' + Digest::MD5.hexdigest(params[:location].to_s)) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}") } + it { is_expected.to contain_concat__fragment("server2-500-#{Digest::MD5.hexdigest(params[:location].to_s)}") } end end @@ -163,12 +166,12 @@ 'test3' => { 'subtest1' => ['"sub test value1a"', '"sub test value1b"'], 'subtest2' => '"sub test value2"' } }, match: [ - %r{^[ ]+test1\s+bar}, - %r{^[ ]+test2\s+foobar}, - %r{^[ ]+test2\s+barbaz}, - %r{^[ ]+test3\s+subtest1 "sub test value1a"}, - %r{^[ ]+test3\s+subtest1 "sub test value1b"}, - %r{^[ ]+test3\s+subtest2 "sub test value2"} + %r{^ +test1\s+bar}, + %r{^ +test2\s+foobar}, + %r{^ +test2\s+barbaz}, + %r{^ +test3\s+subtest1 "sub test value1a"}, + %r{^ +test3\s+subtest1 "sub test value1b"}, + %r{^ +test3\s+subtest2 "sub test value2"} ] }, { @@ -190,9 +193,9 @@ '^/users/(.*)$ /show?user=$1? last' ], match: [ - %r{rewrite \^\(\/download\/\.\*\)\/media\/\(\.\*\)\\\.\.\*\$ \$1\/mp3\/\$2\.mp3 last}, - %r{rewrite \^\(\/download\/\.\*\)\/media\/\(\.\*\)\\\.\.\*\$ \$1\/mp3\/\$2\.ra last}, - %r{rewrite \^\/users\/\(\.\*\)\$ \/show\?user=\$1\? last} + %r{rewrite \^\(/download/\.\*\)/media/\(\.\*\)\\\.\.\*\$ \$1/mp3/\$2\.mp3 last}, + %r{rewrite \^\(/download/\.\*\)/media/\(\.\*\)\\\.\.\*\$ \$1/mp3/\$2\.ra last}, + %r{rewrite \^/users/\(\.\*\)\$ /show\?user=\$1\? last} ] }, { @@ -242,10 +245,10 @@ let(:default_params) { { location: 'location', proxy: 'proxy_value', server: 'server1' } } let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) } - it { is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}") } it param[:title] do - fragment = 'server1-500-' + Digest::MD5.hexdigest(params[:location].to_s) + fragment = "server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}" matches = Array(param[:match]) if matches.all? { |m| m.is_a? Regexp } @@ -256,7 +259,7 @@ end Array(param[:notmatch]).each do |item| - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)).without_content(item) + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}").without_content(item) end end end @@ -296,12 +299,12 @@ 'test3' => { 'subtest1' => ['"sub test value1a"', '"sub test value1b"'], 'subtest2' => '"sub test value2"' } }, match: [ - %r{^[ ]+test1\s+bar}, - %r{^[ ]+test2\s+foobar}, - %r{^[ ]+test2\s+barbaz}, - %r{^[ ]+test3\s+subtest1 "sub test value1a"}, - %r{^[ ]+test3\s+subtest1 "sub test value1b"}, - %r{^[ ]+test3\s+subtest2 "sub test value2"} + %r{^ +test1\s+bar}, + %r{^ +test2\s+foobar}, + %r{^ +test2\s+barbaz}, + %r{^ +test3\s+subtest1 "sub test value1a"}, + %r{^ +test3\s+subtest1 "sub test value1b"}, + %r{^ +test3\s+subtest2 "sub test value2"} ] }, { @@ -319,10 +322,10 @@ let(:default_params) { { location: 'location', proxy: 'proxy_value', server: 'server1' } } let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) } - it { is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}") } it param[:title] do - fragment = 'server1-500-' + Digest::MD5.hexdigest(params[:location].to_s) + fragment = "server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}" matches = Array(param[:match]) if matches.all? { |m| m.is_a? Regexp } @@ -333,12 +336,12 @@ end Array(param[:notmatch]).each do |item| - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)).without_content(item) + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}").without_content(item) end end it 'ends with a closing brace' do - fragment = 'server1-500-' + Digest::MD5.hexdigest(params[:location].to_s) + fragment = "server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}" content = catalogue.resource('concat::fragment', fragment).send(:parameters)[:content] expect(content.split("\n").reject { |l| l =~ %r{^(\s*#|$)} }.last.strip).to eq('}') end @@ -358,18 +361,21 @@ context 'location_alias template with default params' do let(:params) { default_params } - it { is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('location')}") } + it 'sets alias' do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')). + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('location')}"). with_content(%r{^\s+alias\s+value;}) end + it "doesn't set try_files" do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')). + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('location')}"). without_content(%r{^\s+try_files[^;]+;}) end + it "doesn't set autoindex" do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')). - without_content(%r{^[ ]+autoindex[^;]+;}) + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('location')}"). + without_content(%r{^ +autoindex[^;]+;}) end end @@ -408,9 +414,10 @@ 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('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}") } + it param[:title] do - fragment = 'server1-500-' + Digest::MD5.hexdigest(params[:location].to_s) + fragment = "server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}" matches = Array(param[:match]) if matches.all? { |m| m.is_a? Regexp } @@ -421,7 +428,7 @@ end Array(param[:notmatch]).each do |item| - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)).without_content(item) + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}").without_content(item) end end end @@ -439,9 +446,10 @@ context 'location_add_header template with default params' do let(:params) { default_params } - it { is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('location')}") } + it 'doesn\'t add any add_header lines' do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')). + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('location')}"). without_content(%r{add_header}) end end @@ -458,11 +466,11 @@ end it 'contains 3 add_header lines' do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')). + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('location')}"). with_content(%r{^\s+add_header\s+"header 1"\s+"test value 1";$}) - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')). + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('location')}"). with_content(%r{^\s+add_header\s+"header 2"\s+"test value 2" tv2;$}) - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')). + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('location')}"). with_content(%r{^\s+add_header\s+"header 3"\s+'test value 3' tv3;$}) end end @@ -478,7 +486,7 @@ end it 'contain gzip_static if set' do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')). + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('location')}"). with_content(%r{^\s+gzip_static\s+on;$}) end end @@ -521,9 +529,10 @@ 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('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}") } + it param[:title] do - fragment = 'server1-500-' + Digest::MD5.hexdigest(params[:location].to_s) + fragment = "server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}" matches = Array(param[:match]) if matches.all? { |m| m.is_a? Regexp } @@ -534,7 +543,7 @@ end Array(param[:notmatch]).each do |item| - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)).without_content(item) + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}").without_content(item) end end end @@ -543,40 +552,44 @@ context "when autoindex is 'on'" do let(:params) { default_params.merge(autoindex: 'on') } - it { is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('location')}") } + it 'sets autoindex' do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')). - with_content(%r{^[ ]+autoindex\s+on;}) + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('location')}"). + with_content(%r{^ +autoindex\s+on;}) end end context 'when autoindex is not set' do let(:params) { default_params } - it { is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('location')}") } + it 'does not set autoindex' do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')). - without_content(%r{^[ ]+autoindex[^;]+;}) + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('location')}"). + without_content(%r{^ +autoindex[^;]+;}) end end context "when autoindex_localtime is 'on'" do let(:params) { default_params.merge(autoindex_localtime: 'on') } - it { is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('location')}") } + it 'sets autoindex_localtime' do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')). - with_content(%r{^[ ]+autoindex_localtime\s+on;}) + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('location')}"). + with_content(%r{^ +autoindex_localtime\s+on;}) end end context 'when autoindex_localtime is not set' do let(:params) { default_params } - it { is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('location')}") } + it 'does not set autoindex_localtime' do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')). - without_content(%r{^[ ]+autoindex_localtime[^;]+;}) + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('location')}"). + without_content(%r{^ +autoindex_localtime[^;]+;}) end end end @@ -604,9 +617,10 @@ let(:default_params) { { location: 'location', location_custom_cfg: { 'test1' => 'value1' }, server: 'server1' } } let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) } - it { is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}") } + it param[:title] do - fragment = 'server1-500-' + Digest::MD5.hexdigest(params[:location].to_s) + fragment = "server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}" matches = Array(param[:match]) if matches.all? { |m| m.is_a? Regexp } @@ -617,7 +631,7 @@ end Array(param[:notmatch]).each do |item| - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)).without_content(item) + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}").without_content(item) end end end @@ -668,9 +682,10 @@ 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('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}") } + it param[:title] do - fragment = 'server1-500-' + Digest::MD5.hexdigest(params[:location].to_s) + fragment = "server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}" matches = Array(param[:match]) if matches.all? { |m| m.is_a? Regexp } @@ -681,7 +696,7 @@ end Array(param[:notmatch]).each do |item| - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)).without_content(item) + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}").without_content(item) end end end @@ -690,20 +705,22 @@ context "when fastcgi_script is 'value'" do let(:params) { default_params.merge(fastcgi_script: 'value') } - it { is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}") } + it 'sets fastcgi_script' do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)). - with_content(%r{^[ ]+fastcgi_param\s+SCRIPT_FILENAME\s+value;}) + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}"). + with_content(%r{^ +fastcgi_param\s+SCRIPT_FILENAME\s+value;}) end end context 'when fastcgi_script is not set' do let(:params) { default_params } - it { is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}") } + it 'does not set fastcgi_script' do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)). - without_content(%r{^[ ]+fastcgi_param\s+SCRIPT_FILENAME\s+.+?;}) + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}"). + without_content(%r{^ +fastcgi_param\s+SCRIPT_FILENAME\s+.+?;}) end end @@ -711,7 +728,7 @@ let(:params) { default_params.merge(fastcgi_param: { 'CUSTOM_PARAM' => 'value', 'CUSTOM_PARAM2' => 'value2' }) } it 'sets fastcgi_param' do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)). + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}"). with_content(%r{fastcgi_param\s+CUSTOM_PARAM\s+value;}). with_content(%r{fastcgi_param\s+CUSTOM_PARAM2\s+value2;}) end @@ -721,7 +738,7 @@ let(:params) { default_params.merge(fastcgi_param: { 'HTTP_PROXY' => '""' }) } it 'sets fastcgi_param' do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)). + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}"). with_content(%r{fastcgi_param\s+HTTP_PROXY\s+"";}) end end @@ -730,12 +747,13 @@ let(:params) { default_params } it 'does not set fastcgi_param' do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)). + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}"). without_content(%r{fastcgi_param\s+CUSTOM_PARAM\s+.+?;}). without_content(%r{fastcgi_param\s+CUSTOM_PARAM2\s+.+?;}) end + it 'does not add comment # Enable custom fastcgi_params' do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)). + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}"). without_content(%r{# Enable custom fastcgi_params\s+}) end end @@ -785,9 +803,10 @@ 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('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}") } + it param[:title] do - fragment = 'server1-500-' + Digest::MD5.hexdigest(params[:location].to_s) + fragment = "server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}" matches = Array(param[:match]) if matches.all? { |m| m.is_a? Regexp } @@ -798,7 +817,7 @@ end Array(param[:notmatch]).each do |item| - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)).without_content(item) + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}").without_content(item) end end end @@ -808,7 +827,7 @@ let(:params) { default_params.merge(uwsgi_param: { 'CUSTOM_PARAM' => 'value', 'CUSTOM_PARAM2' => 'value2' }) } it 'sets uwsgi_param' do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)). + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}"). with_content(%r{uwsgi_param\s+CUSTOM_PARAM\s+value;}). with_content(%r{uwsgi_param\s+CUSTOM_PARAM2\s+value2;}) end @@ -818,7 +837,7 @@ let(:params) { default_params.merge(uwsgi_param: { 'HTTP_PROXY' => '""' }) } it 'sets uwsgi_param' do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)). + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}"). with_content(%r{uwsgi_param\s+HTTP_PROXY\s+"";}) end end @@ -827,7 +846,7 @@ let(:params) { default_params } it 'does not set uwsgi_param' do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)). + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}"). without_content(%r{^\s+uwsgi_param\s+}) end end @@ -1008,9 +1027,10 @@ let(:default_params) { { location: 'location', proxy: 'proxy_value', server: 'server1' } } let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) } - it { is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}") } + it param[:title] do - fragment = 'server1-500-' + Digest::MD5.hexdigest(params[:location].to_s) + fragment = "server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}" matches = Array(param[:match]) if matches.all? { |m| m.is_a? Regexp } @@ -1021,7 +1041,7 @@ end Array(param[:notmatch]).each do |item| - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)).without_content(item) + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}").without_content(item) end end end @@ -1038,7 +1058,7 @@ } end - it { is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')).with_content(%r{proxy_cache_valid\s+10m;}) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('location')}").with_content(%r{proxy_cache_valid\s+10m;}) } end end @@ -1046,7 +1066,7 @@ let(:params) { { location: 'location', stub_status: true, server: 'server1' } } it do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)). + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}"). with_content(%r{stub_status\s+on}) end end @@ -1069,8 +1089,9 @@ end it { is_expected.not_to contain_file('/etc/nginx/mycustomparams') } + it do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)). + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}"). with_content(%r{include\s+/etc/nginx/mycustomparams;}) end end @@ -1086,8 +1107,9 @@ end it { is_expected.not_to contain_file('/etc/nginx/fastcgi.conf') } + it do - is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest(params[:location].to_s)). + is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest(params[:location].to_s)}"). without_content(%r{include\s+/etc/nginx/fastcgi.conf;}) end end @@ -1113,25 +1135,25 @@ context 'when ssl_only => true' do let(:params) { { ssl_only: true, server: 'server1', www_root: '/' } } - it { is_expected.not_to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('rspec-test')) } + it { is_expected.not_to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('rspec-test')}") } end context 'when ssl_only => false' do let(:params) { { ssl_only: false, server: 'server1', www_root: '/' } } - it { is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('rspec-test')) } + it { is_expected.to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('rspec-test')}") } end context 'when ssl => true' do let(:params) { { ssl: true, server: 'server1', www_root: '/' } } - it { is_expected.to contain_concat__fragment('server1-800-' + Digest::MD5.hexdigest('rspec-test') + '-ssl') } + it { is_expected.to contain_concat__fragment("server1-800-#{Digest::MD5.hexdigest('rspec-test')}-ssl") } end context 'when ssl => false' do let(:params) { { ssl: false, server: 'server1', www_root: '/' } } - it { is_expected.not_to contain_concat__fragment('server1-800-' + Digest::MD5.hexdigest('rspec-test') + '-ssl') } + it { is_expected.not_to contain_concat__fragment("server1-800-#{Digest::MD5.hexdigest('rspec-test')}-ssl") } end context 'www_root and proxy are set' do @@ -1156,8 +1178,8 @@ } end - it { is_expected.to contain_concat__fragment('www_rspec-server_com-500-' + Digest::MD5.hexdigest('www.rspec-location.com')).with_target('/etc/nginx/sites-available/www_rspec-server_com.conf') } - it { is_expected.to contain_concat__fragment('www_rspec-server_com-800-' + Digest::MD5.hexdigest('www.rspec-location.com') + '-ssl').with_target('/etc/nginx/sites-available/www_rspec-server_com.conf') } + it { is_expected.to contain_concat__fragment("www_rspec-server_com-500-#{Digest::MD5.hexdigest('www.rspec-location.com')}").with_target('/etc/nginx/sites-available/www_rspec-server_com.conf') } + it { is_expected.to contain_concat__fragment("www_rspec-server_com-800-#{Digest::MD5.hexdigest('www.rspec-location.com')}-ssl").with_target('/etc/nginx/sites-available/www_rspec-server_com.conf') } end context 'when ensure => absent' do @@ -1169,7 +1191,7 @@ } end - it { is_expected.not_to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('rspec-test')) } + it { is_expected.not_to contain_concat__fragment("server1-500-#{Digest::MD5.hexdigest('rspec-test')}") } end context 'when ensure => absent and ssl => true' do @@ -1182,7 +1204,7 @@ } end - it { is_expected.not_to contain_concat__fragment('server1-800-' + Digest::MD5.hexdigest('rspec-test') + '-ssl') } + it { is_expected.not_to contain_concat__fragment("server1-800-#{Digest::MD5.hexdigest('rspec-test')}-ssl") } end end end diff --git a/spec/defines/resource_mailhost_spec.rb b/spec/defines/resource_mailhost_spec.rb index 0ea9bd38b..e1c81b74b 100644 --- a/spec/defines/resource_mailhost_spec.rb +++ b/spec/defines/resource_mailhost_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'nginx::resource::mailhost' do @@ -21,17 +23,19 @@ it { is_expected.to contain_class('nginx') } it { is_expected.to contain_concat("/etc/nginx/conf.mail.d/#{title}.conf").that_requires('File[/etc/nginx/conf.mail.d]') } + it do is_expected.to contain_concat("/etc/nginx/conf.mail.d/#{title}.conf").with('owner' => 'root', 'group' => 'root', - 'mode' => '0644') + 'mode' => '0644') end + it { is_expected.to contain_concat__fragment("#{title}-header") } it { is_expected.not_to contain_concat__fragment("#{title}-ssl") } end describe 'absent assumption' do - let(:params) { default_params.merge('ensure'.to_sym => 'absent') } + let(:params) { default_params.merge(ensure: 'absent') } it { is_expected.to contain_class('nginx') } it { is_expected.to contain_concat("/etc/nginx/conf.mail.d/#{title}.conf").with('ensure' => 'absent') } @@ -190,6 +194,7 @@ let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) } it { is_expected.to contain_concat__fragment("#{title}-header") } + it param[:title] do matches = Array(param[:match]) @@ -237,6 +242,7 @@ let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) } it { is_expected.to contain_concat__fragment("#{title}-header") } + it param[:title] do matches = Array(param[:match]) @@ -277,6 +283,7 @@ let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) } it { is_expected.to contain_concat__fragment("#{title}-header") } + it param[:title] do matches = Array(param[:match]) @@ -317,6 +324,7 @@ let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) } it { is_expected.to contain_concat__fragment("#{title}-header") } + it param[:title] do matches = Array(param[:match]) @@ -472,6 +480,7 @@ let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) } it { is_expected.to contain_concat__fragment("#{title}-header") } + it param[:title] do matches = Array(param[:match]) @@ -595,6 +604,7 @@ let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) } it { is_expected.to contain_concat__fragment("#{title}-ssl") } + it param[:title] do matches = Array(param[:match]) @@ -633,6 +643,7 @@ expect(content).to include('listen *:587 ssl;') end end + context 'when version comes from parameter' do let(:pre_condition) { ['class { "nginx": nginx_version => "1.16.0"}'] } diff --git a/spec/defines/resource_map_spec.rb b/spec/defines/resource_map_spec.rb index 397527bc9..4f431e0b4 100644 --- a/spec/defines/resource_map_spec.rb +++ b/spec/defines/resource_map_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'nginx::resource::map' do @@ -33,9 +35,10 @@ let(:params) { default_params } it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-map.conf").that_requires('File[/etc/nginx/conf.d]') } + it do is_expected.to contain_file("/etc/nginx/conf.d/#{title}-map.conf").with( - 'owner' => 'root', + 'owner' => 'root', 'group' => 'root', 'mode' => '0644', 'ensure' => 'file', @@ -52,9 +55,10 @@ 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', + 'owner' => 'root', 'group' => 'root', 'mode' => '0644', 'ensure' => 'file', @@ -119,7 +123,7 @@ }, { title: 'should contain mappings in input order when supplied as an array of hashes', - attr: 'mappings', + attr: 'mappings', value: [ { 'key' => 'foo', 'value' => 'pool_b' }, { 'key' => 'bar', 'value' => 'pool_c' }, @@ -136,6 +140,7 @@ let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) } it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-map.conf").with_mode('0644') } + it param[:title] do verify_contents(catalogue, "/etc/nginx/conf.d/#{title}-map.conf", Array(param[:match])) Array(param[:notmatch]).each do |item| diff --git a/spec/defines/resource_server_spec.rb b/spec/defines/resource_server_spec.rb index 4e104fa9c..87d03bf52 100644 --- a/spec/defines/resource_server_spec.rb +++ b/spec/defines/resource_server_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'nginx::resource::server' do @@ -30,19 +32,22 @@ let(:params) { default_params } it { is_expected.to contain_class('nginx') } + it do is_expected.to contain_concat("/etc/nginx/sites-available/#{title}.conf").with('owner' => 'root', 'group' => 'root', 'mode' => '0644') end + it { is_expected.to contain_concat__fragment("#{title}-header").with_content(%r{access_log\s+/var/log/nginx/www\.rspec\.example\.com\.access\.log;}) } it { is_expected.to contain_concat__fragment("#{title}-header").with_content(%r{error_log\s+/var/log/nginx/www\.rspec\.example\.com\.error\.log}) } it { is_expected.to contain_concat__fragment("#{title}-footer") } it { is_expected.to contain_nginx__resource__location("#{title}-default") } it { is_expected.not_to contain_file('/etc/nginx/fastcgi.conf') } + it do is_expected.to contain_file("#{title}.conf symlink").with('ensure' => 'link', - 'path' => "/etc/nginx/sites-enabled/#{title}.conf", + 'path' => "/etc/nginx/sites-enabled/#{title}.conf", 'target' => "/etc/nginx/sites-available/#{title}.conf") end end @@ -52,6 +57,7 @@ let(:params) { default_params } it { is_expected.to contain_class('nginx') } + it do is_expected.to contain_concat("/etc/nginx/conf.d/#{title}.conf").with('owner' => 'root', 'group' => 'root', @@ -391,6 +397,7 @@ let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) } it { is_expected.to contain_concat__fragment("#{title}-header") } + it param[:title] do matches = Array(param[:match]) @@ -448,6 +455,7 @@ let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) } it { is_expected.to contain_concat__fragment("#{title}-header") } + it param[:title] do matches = Array(param[:match]) @@ -506,6 +514,7 @@ let(:params) { default_params.merge(param[:attr].to_sym => param[:value], ssl: true, ssl_cert: '/tmp/dummy.crt', ssl_key: '/tmp/dummy.key', listen_port: 443) } it { is_expected.to contain_concat__fragment("#{title}-ssl-header") } + it param[:title] do matches = Array(param[:match]) @@ -571,6 +580,7 @@ let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) } it { is_expected.to contain_concat__fragment("#{title}-footer") } + it param[:title] do matches = Array(param[:match]) @@ -605,6 +615,7 @@ let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) } it { is_expected.to contain_concat__fragment("#{title}-footer") } + it param[:title] do matches = Array(param[:match]) @@ -639,6 +650,7 @@ it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{ ssl on;}) } end + context 'with fact nginx_version=1.14.1' do let(:facts) { facts.merge(nginx_version: '1.14.1') } @@ -1045,12 +1057,13 @@ context "when #{param[:attr]} is #{param[:value]}" do let :params do default_params.merge(param[:attr].to_sym => param[:value], - :ssl => true, - :ssl_key => 'dummy.key', - :ssl_cert => 'dummy.crt') + :ssl => true, + :ssl_key => 'dummy.key', + :ssl_cert => 'dummy.crt') end it { is_expected.to contain_concat__fragment("#{title}-ssl-header") } + it param[:title] do matches = Array(param[:match]) @@ -1124,12 +1137,13 @@ context "when #{param[:attr]} is #{param[:value]}" do let :params do default_params.merge(param[:attr].to_sym => param[:value], - :ssl => true, - :ssl_key => 'dummy.key', - :ssl_cert => 'dummy.crt') + :ssl => true, + :ssl_key => 'dummy.key', + :ssl_cert => 'dummy.crt') end it { is_expected.to contain_concat__fragment("#{title}-ssl-footer") } + it param[:title] do matches = Array(param[:match]) @@ -1449,6 +1463,7 @@ it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{error_log\s+/var/log/nginx/ssl-www\.rspec\.example\.com\.error\.log}) } it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{ssl_verify_client\s+optional;}) } end + context 'when passenger_cgi_param is set' do let :params do default_params.merge(passenger_cgi_param: { 'test1' => 'test value 1', 'test2' => 'test value 2', 'test3' => 'test value 3' }) diff --git a/spec/defines/resource_snippet_spec.rb b/spec/defines/resource_snippet_spec.rb index 80f517dd0..0c4ac88cc 100644 --- a/spec/defines/resource_snippet_spec.rb +++ b/spec/defines/resource_snippet_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'nginx::resource::snippet' do diff --git a/spec/defines/resource_stream_spec.rb b/spec/defines/resource_stream_spec.rb index adcad607e..bdeb25205 100644 --- a/spec/defines/resource_stream_spec.rb +++ b/spec/defines/resource_stream_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'nginx::resource::streamhost' do @@ -27,11 +29,13 @@ let(:params) { default_params } it { is_expected.to contain_class('nginx') } + it do is_expected.to contain_concat("/etc/nginx/streams-available/#{title}.conf").with('owner' => 'root', 'group' => 'root', - 'mode' => '0644') + 'mode' => '0644') end + it do is_expected.to contain_file("#{title}.conf symlink").with('ensure' => 'link', 'path' => "/etc/nginx/streams-enabled/#{title}.conf", @@ -44,10 +48,11 @@ let(:params) { default_params } it { is_expected.to contain_class('nginx') } + it do is_expected.to contain_concat("/etc/nginx/conf.stream.d/#{title}.conf").with('owner' => 'root', 'group' => 'root', - 'mode' => '0644') + 'mode' => '0644') end end @@ -132,6 +137,7 @@ let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) } it { is_expected.to contain_concat__fragment("#{title}-header") } + it param[:title] do matches = Array(param[:match]) diff --git a/spec/defines/resource_upstream_spec.rb b/spec/defines/resource_upstream_spec.rb index fc7e5113c..620137d94 100644 --- a/spec/defines/resource_upstream_spec.rb +++ b/spec/defines/resource_upstream_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'nginx::resource::upstream' do @@ -46,10 +48,12 @@ it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_concat("/etc/nginx/conf.d/#{title}-upstream.conf"). that_requires('File[/etc/nginx/conf.d]') } + it { is_expected.to contain_concat__fragment("#{title}_upstream_header"). with_content(%r{upstream #{title}}). @@ -58,6 +62,7 @@ 'order' => 10 ) } + it { is_expected.to contain_concat__fragment("#{title}_upstream_member_#{params[:members].keys[0]}"). with( @@ -65,6 +70,7 @@ 'order' => 40 ) } + it { is_expected.to contain_concat__fragment("#{title}_upstream_footer"). with( @@ -86,10 +92,12 @@ it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_concat("#{conf_d_path}/#{title}-upstream.conf"). that_requires("File[#{conf_d_path}]") } + it { is_expected.to contain_concat__fragment("#{title}_upstream_header"). with_content(%r{upstream #{title}}). @@ -98,6 +106,7 @@ 'order' => 10 ) } + it { is_expected.to contain_concat__fragment("#{title}_upstream_member_#{params[:members].keys[0]}"). with( @@ -105,6 +114,7 @@ 'order' => 40 ) } + it { is_expected.to contain_concat__fragment("#{title}_upstream_footer"). with( @@ -129,18 +139,22 @@ it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_concat("#{conf_d_path}/#{title}-upstream.conf"). with_mode('0644') } + it { is_expected.to contain_concat__fragment("#{title}_upstream_header"). with_content("# MANAGED BY PUPPET\nupstream #{title} {\n") } + it { is_expected.to contain_concat__fragment("#{title}_upstream_member_#{params[:members].keys[0]}"). with_content(" server #{params[:members].keys[0]}:80;\n") } + it { is_expected.to contain_concat__fragment("#{title}_upstream_footer"). with_content("}\n") @@ -242,26 +256,30 @@ it { is_expected.to raise_error(Puppet::Error, %r{#{upstream_parameter[:fails][upstreamcontext.to_sym]}}) } + next end it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_concat("#{conf_d_path}/#{title}-upstream.conf"). with_mode('0644') } + it { is_expected.to contain_concat__fragment("#{title}_upstream_header"). with_content("# MANAGED BY PUPPET\nupstream #{title} {\n") } + it { is_expected.to contain_concat__fragment("#{title}_upstream_member_#{params[:members].keys[0]}"). with_content(" server #{params[:members].keys[0]}:80;\n") } - if upstream_parameter[:match] != false + if upstream_parameter[:match] it { is_expected.to contain_concat__fragment("#{title}_upstream_footer"). with_content(" #{upstream_parameter[:match]};\n}\n") @@ -378,24 +396,29 @@ it { is_expected.to raise_error(Puppet::Error, %r{#{upstream_member_parameter[:fails][upstreamcontext.to_sym]}}) } + next end it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_concat("#{conf_d_path}/#{title}-upstream.conf"). with_mode('0644') } + it { is_expected.to contain_concat__fragment("#{title}_upstream_header"). with_content("# MANAGED BY PUPPET\nupstream #{title} {\n") } + it { is_expected.to contain_concat__fragment("#{title}_upstream_member_#{upstream_member_parameter[:value].keys[0]}"). with_content(" server #{upstream_member_parameter[:match]}\n") } + it { is_expected.to contain_concat__fragment("#{title}_upstream_footer"). with_content("}\n") @@ -439,10 +462,12 @@ it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_concat("#{conf_d_path}/#{title}-upstream.conf"). with_mode('0644') } + if upstream_cfg_extension[:fragment] == 'header' it { is_expected.to contain_concat__fragment("#{title}_upstream_header"). @@ -458,6 +483,7 @@ is_expected.to contain_concat__fragment("#{title}_upstream_member_#{params[:members].keys[0]}"). with_content(" server #{params[:members].keys[0]}:80;\n") } + if upstream_cfg_extension[:fragment] == 'footer' it { is_expected.to contain_concat__fragment("#{title}_upstream_footer"). @@ -479,6 +505,7 @@ it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_concat("#{conf_d_path}/#{title}-upstream.conf"). with_ensure('absent') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fb5f0cbea..4d617f393 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,17 +1,17 @@ +# frozen_string_literal: true + # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ # puppetlabs_spec_helper will set up coverage if the env variable is set. # We want to do this if lib exists and it hasn't been explicitly set. -ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../../lib', __FILE__)) +ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../lib', __dir__)) require 'voxpupuli/test/spec_helper' if File.exist?(File.join(__dir__, 'default_module_facts.yml')) facts = YAML.safe_load(File.read(File.join(__dir__, 'default_module_facts.yml'))) - if facts - facts.each do |name, value| - add_custom_fact name.to_sym, value - end + facts&.each do |name, value| + add_custom_fact name.to_sym, value end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 50fa874cd..711094921 100755 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'voxpupuli/acceptance/spec_helper_acceptance' configure_beaker do |host| diff --git a/spec/type_aliases/debugconnection_spec.rb b/spec/type_aliases/debugconnection_spec.rb index d9d4cb4cd..71a4c9825 100644 --- a/spec/type_aliases/debugconnection_spec.rb +++ b/spec/type_aliases/debugconnection_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'Nginx::DebugConnection' do diff --git a/spec/type_aliases/size_spec.rb b/spec/type_aliases/size_spec.rb index fc5ed1be4..ea04586d2 100644 --- a/spec/type_aliases/size_spec.rb +++ b/spec/type_aliases/size_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'Nginx::Size' do diff --git a/spec/type_aliases/time_spec.rb b/spec/type_aliases/time_spec.rb index e768f4f1d..e2ac85b0f 100644 --- a/spec/type_aliases/time_spec.rb +++ b/spec/type_aliases/time_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'Nginx::Time' do diff --git a/spec/type_aliases/upstreamcustomparameters_spec.rb b/spec/type_aliases/upstreamcustomparameters_spec.rb index 9b194b7c0..ec40b3f7c 100644 --- a/spec/type_aliases/upstreamcustomparameters_spec.rb +++ b/spec/type_aliases/upstreamcustomparameters_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'Nginx::UpstreamCustomParameters' do diff --git a/spec/type_aliases/upstreammemberserver_spec.rb b/spec/type_aliases/upstreammemberserver_spec.rb index 599f2d94f..43f881457 100644 --- a/spec/type_aliases/upstreammemberserver_spec.rb +++ b/spec/type_aliases/upstreammemberserver_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'Nginx::UpstreamMemberServer' do diff --git a/spec/type_aliases/upstreamstickyzone_spec.rb b/spec/type_aliases/upstreamstickyzone_spec.rb index e8008d638..f2f4e52f0 100644 --- a/spec/type_aliases/upstreamstickyzone_spec.rb +++ b/spec/type_aliases/upstreamstickyzone_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'Nginx::UpstreamStickyZone' do diff --git a/spec/type_aliases/upstreamzone_spec.rb b/spec/type_aliases/upstreamzone_spec.rb index 7bf61caf8..72d5fe8b6 100644 --- a/spec/type_aliases/upstreamzone_spec.rb +++ b/spec/type_aliases/upstreamzone_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'Nginx::UpstreamZone' do diff --git a/spec/unit/facter/util/fact_nginx_version_spec.rb b/spec/unit/facter/util/fact_nginx_version_spec.rb index 3d90493e6..94cff3635 100644 --- a/spec/unit/facter/util/fact_nginx_version_spec.rb +++ b/spec/unit/facter/util/fact_nginx_version_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Facter::Util::Fact do @@ -5,36 +7,44 @@ context 'neither nginx or openresty in path' do before do - allow(Facter::Util::Resolution).to receive(:which).with('nginx') { false } - allow(Facter::Util::Resolution).to receive(:which).with('openresty') { false } + allow(Facter::Util::Resolution).to receive(:which).with('nginx').and_return(false) + allow(Facter::Util::Resolution).to receive(:which).with('openresty').and_return(false) end + it { expect(Facter.fact(:nginx_version).value).to eq(nil) } end + context 'nginx' do context 'with current version output format' do before do - allow(Facter::Util::Resolution).to(receive(:which).with('nginx').twice) { true } - allow(Facter::Util::Resolution).to receive(:exec).with('nginx -v 2>&1') { 'nginx version: nginx/1.8.1' } + allow(Facter::Util::Resolution).to(receive(:which).with('nginx').twice).and_return(true) + allow(Facter::Util::Resolution).to receive(:exec).with('nginx -v 2>&1').and_return('nginx version: nginx/1.8.1') end + it { expect(Facter.fact(:nginx_version).value).to eq('1.8.1') } end + context 'with old version output format' do before do - allow(Facter::Util::Resolution).to(receive(:which).with('nginx').twice) { true } - allow(Facter::Util::Resolution).to receive(:exec).with('nginx -v 2>&1') { 'nginx: nginx version: nginx/0.7.0' } + allow(Facter::Util::Resolution).to(receive(:which).with('nginx').twice).and_return(true) + allow(Facter::Util::Resolution).to receive(:exec).with('nginx -v 2>&1').and_return('nginx: nginx version: nginx/0.7.0') end + it { expect(Facter.fact(:nginx_version).value).to eq('0.7.0') } end end + context 'openresty' do context 'with current version output format' do before do - allow(Facter::Util::Resolution).to(receive(:which).with('nginx').twice) { false } - allow(Facter::Util::Resolution).to receive(:which).with('openresty') { true } - allow(Facter::Util::Resolution).to receive(:exec).with('openresty -v 2>&1') { 'nginx version: openresty/1.11.2.1' } + allow(Facter::Util::Resolution).to(receive(:which).with('nginx').twice).and_return(false) + allow(Facter::Util::Resolution).to receive(:which).with('openresty').and_return(true) + allow(Facter::Util::Resolution).to receive(:exec).with('openresty -v 2>&1').and_return('nginx version: openresty/1.11.2.1') end + it { expect(Facter.fact(:nginx_version).value).to eq('1.11.2.1') } end + context 'with old version output format' do # rubocop:disable RSpec/EmptyExampleGroup # Openresty never used the old format as far as I can find, no point testing end