Merge from master

This commit is contained in:
Marin Vintila 2015-05-08 12:04:22 +03:00
commit 5624e4ca55
42 changed files with 525 additions and 393 deletions

View file

@ -1,3 +1,7 @@
fixtures:
symlinks:
nginx: "#{source_dir}"
forge_modules:
apt: "puppetlabs/apt"
concat: "puppetlabs/concat"
stdlib: "puppetlabs/stdlib"

2
.gitignore vendored
View file

@ -1,8 +1,6 @@
files/server_test.crt
files/server_test.pem
pkg/
.librarian/
.tmp/
pkg/
Gemfile.lock
spec/fixtures/

4
.puppet-lint.rc Normal file
View file

@ -0,0 +1,4 @@
--fail-on-warnings
--relative
--no-80chars-check
--no-class_inherits_from_params_class-check

View file

@ -4,22 +4,29 @@ branches:
- refactor
- gh-pages
language: ruby
script: "bundle exec rake --rakefile $PWD/.travis/Rakefile spec SPEC_OPTS='--format documentation'"
rvm:
- 1.9.3
- 2.0.0
gemfile: .travis/Gemfile
env:
matrix:
- PUPPET_GEM_VERSION="~> 2.7.0"
- PUPPET_GEM_VERSION="~> 3.0"
script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--format documentation'"
bundler_args: --without rake
matrix:
exclude:
fast_finish: true
include:
- rvm: 1.8.7
env: PUPPET_GEM_VERSION="~> 2.7.0"
- rvm: 1.8.7
env: PUPPET_GEM_VERSION="~> 3.0"
- rvm: 1.9.3
env: PUPPET_GEM_VERSION="~> 2.7.0"
gemfile: .travis/Gemfile
env: PUPPET_GEM_VERSION="~> 3.0"
- rvm: 2.0.0
env: PUPPET_GEM_VERSION="~> 3.0"
- rvm: 2.1.0
env: PUPPET_GEM_VERSION="~> 3.0"
- rvm: 2.1.0
env: PUPPET_GEM_VERSION="~> 3.5.0" FUTURE_PARSER="yes"
allow_failures:
- rvm: 1.8.7
env: PUPPET_GEM_VERSION="~> 2.7.0"
gemfile: .travis/Gemfile
- rvm: 1.8.7
env: PUPPET_GEM_VERSION="~> 3.0"
- rvm: 2.1.0
env: PUPPET_GEM_VERSION="~> 3.5.0" FUTURE_PARSER="yes"
notifications:
email: false

View file

@ -1,14 +0,0 @@
source 'https://rubygems.org'
group :rake do
gem 'puppetlabs_spec_helper'
gem 'librarian-puppet', '<1.1.0'
gem 'open3_backport', :platforms => :ruby_18
gem 'json', :platforms => :ruby_18
end
if puppetversion = ENV['PUPPET_GEM_VERSION']
gem 'puppet', puppetversion, :require => false
else
gem 'puppet', :require => false
end

View file

@ -1,8 +0,0 @@
require 'puppetlabs_spec_helper/rake_tasks'
# use librarian-puppet to manage fixtures instead of .fixtures.yml
# offers more possibilities like explicit version management, forge downloads,...
task :librarian_spec_prep do
sh "librarian-puppet install --path=$PWD/spec/fixtures/modules/"
end
task :spec_prep => :librarian_spec_prep

23
Gemfile
View file

@ -1,13 +1,24 @@
source 'https://rubygems.org'
group :test do
gem 'rest-client', '~> 1.6.8', :require => false, :platforms => :ruby_18
end
group :rake, :test do
gem 'puppetlabs_spec_helper', :require => false
gem 'puppet-blacksmith', :require => false
gem 'rspec-system-puppet', :require => false
end
group :rake do
gem 'puppet', '>=3.0.1'
gem 'rspec-puppet', '>=1.0.1'
gem 'rake', '>=0.9.2.2'
gem 'puppet-lint', '>=0.1.12'
gem 'puppetlabs_spec_helper'
gem 'puppet-blacksmith'
gem 'librarian-puppet', '<1.1.0'
gem 'rspec-system-puppet', :require => false
gem 'puppet-lint', '>=1.0.1'
gem 'rspec-system-serverspec', :require => false
end
if puppetversion = ENV['PUPPET_GEM_VERSION']
gem 'puppet', puppetversion, :require => false
else
gem 'puppet', :require => false
end

11
LICENSE
View file

@ -1,11 +0,0 @@
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

21
LICENSE.md Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 James Fryman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -1,5 +1,5 @@
name 'jfryman-nginx'
version '0.0.9'
version '0.0.10'
source 'http://github.com/jfryman/puppet-nginx'
author 'James Fryman'
license 'Apache License Version 2.0'

View file

@ -1,5 +0,0 @@
forge 'http://forge.puppetlabs.com'
mod 'puppetlabs/stdlib', '>= 3.0.0'
mod 'puppetlabs/apt', '>= 1.0.0'
mod 'puppetlabs/concat', '>= 1.1.0'

View file

@ -1,13 +0,0 @@
FORGE
remote: http://forge.puppetlabs.com
specs:
puppetlabs/apt (1.2.0)
puppetlabs/stdlib (>= 2.2.1)
puppetlabs/concat (1.1.0)
puppetlabs/stdlib (4.1.0)
DEPENDENCIES
puppetlabs/apt (>= 1.0.0)
puppetlabs/concat (>= 1.1.0)
puppetlabs/stdlib (>= 3.0.0)

View file

@ -2,7 +2,8 @@
[![Build Status](https://travis-ci.org/jfryman/puppet-nginx.png)](https://travis-ci.org/jfryman/puppet-nginx)
James Fryman <james@frymanet.com>
* James Fryman <james@frymanet.com>
* Matthew Haughton <matt@3flex.com.au>
This module manages NGINX configuration.
@ -238,6 +239,19 @@ define web::nginx_ssl_with_redirect (
}
```
## Add custom fastcgi_params
```puppet
nginx::resource::location { "some_root":
ensure => present,
location => '/some/url',
fastcgi => "127.0.0.1:9000",
fastcgi_param => {
'APP_ENV' => 'local',
},
}
```
# Call class web::nginx_ssl_with_redirect
```puppet

View file

@ -9,11 +9,4 @@ require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet_blacksmith/rake_tasks'
require 'rspec-system/rake_task'
# use librarian-puppet to manage fixtures instead of .fixtures.yml
# offers more possibilities like explicit version management, forge downloads,...
task :librarian_spec_prep do
sh "librarian-puppet install --path=spec/fixtures/modules/"
end
task :spec_prep => :librarian_spec_prep
task :default => [:clean, :spec]

View file

@ -131,10 +131,10 @@ class nginx::config(
}
file { "${conf_dir}/sites-available":
ensure => directory,
owner => $sites_available_owner,
group => $sites_available_group,
mode => $sites_available_mode,
ensure => directory,
}
if $vhost_purge == true {

View file

@ -96,12 +96,12 @@ class nginx (
$worker_connections = $nginx::params::nx_worker_connections,
$worker_processes = $nginx::params::nx_worker_processes,
$worker_rlimit_nofile = $nginx::params::nx_worker_rlimit_nofile,
$global_owner = $nginx::params::nx_global_owner,
$global_group = $nginx::params::nx_global_group,
$global_mode = $nginx::params::nx_global_mode,
$sites_available_owner = $nginx::params::nx_sites_available_owner,
$sites_available_group = $nginx::params::nx_sites_available_group,
$sites_available_mode = $nginx::params::nx_sites_available_mode,
$global_owner = $nginx::params::global_owner,
$global_group = $nginx::params::global_group,
$global_mode = $nginx::params::global_mode,
$sites_available_owner = $nginx::params::sites_available_owner,
$sites_available_group = $nginx::params::sites_available_group,
$sites_available_mode = $nginx::params::sites_available_mode,
$geo_mappings = {},
$string_mappings = {},
) inherits nginx::params {
@ -131,9 +131,7 @@ class nginx (
if ($proxy_cache_path != false) {
validate_string($proxy_cache_path)
}
if (!is_integer($proxy_cache_levels)) {
fail('$proxy_cache_levels must be an integer.')
}
validate_re($proxy_cache_levels, '^[12](:[12])*$')
validate_string($proxy_cache_keys_zone)
validate_string($proxy_cache_max_size)
validate_string($proxy_cache_inactive)
@ -141,9 +139,7 @@ class nginx (
if ($fastcgi_cache_path != false) {
validate_string($fastcgi_cache_path)
}
if (!is_integer($fastcgi_cache_levels)) {
fail('$fastcgi_cache_levels must be an integer.')
}
validate_re($fastcgi_cache_levels, '^[12](:[12])*$')
validate_string($fastcgi_cache_keys_zone)
validate_string($fastcgi_cache_max_size)
validate_string($fastcgi_cache_inactive)

View file

@ -47,7 +47,7 @@ class nginx::package::debian(
apt::source { 'nginx':
location => 'https://oss-binaries.phusionpassenger.com/apt/passenger',
repos => "main",
repos => 'main',
key => '561F9B9CAC40B2F7',
key_source => 'https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt',
notify => Exec['apt_get_update_for_nginx'],

View file

@ -32,7 +32,7 @@ class nginx::package::redhat (
}
default: {
case $::lsbmajdistrelease {
5, 6: {
5, 6, 7: {
$os_rel = $::lsbmajdistrelease
}
default: {

View file

@ -49,13 +49,13 @@ class nginx::params {
'X-Forwarded-For $proxy_add_x_forwarded_for',
]
$nx_proxy_cache_path = false
$nx_proxy_cache_levels = 1
$nx_proxy_cache_levels = '1'
$nx_proxy_cache_keys_zone = 'd2:100m'
$nx_proxy_cache_max_size = '500m'
$nx_proxy_cache_inactive = '20m'
$nx_fastcgi_cache_path = false
$nx_fastcgi_cache_levels = 1
$nx_fastcgi_cache_levels = '1'
$nx_fastcgi_cache_keys_zone = 'd3:100m'
$nx_fastcgi_cache_max_size = '500m'
$nx_fastcgi_cache_inactive = '20m'

View file

@ -76,6 +76,11 @@ define nginx::resource::geo (
include nginx::params
$root_group = $nginx::params::root_group
$ensure_real = $ensure ? {
'absent' => 'absent',
default => 'file',
}
File {
owner => 'root',
group => $root_group,
@ -83,10 +88,7 @@ define nginx::resource::geo (
}
file { "${nginx::config::conf_dir}/conf.d/${name}-geo.conf":
ensure => $ensure ? {
'absent' => absent,
default => 'file',
},
ensure => $ensure_real,
content => template('nginx/conf.d/geo.erb'),
notify => Class['nginx::service'],
}

View file

@ -31,6 +31,7 @@
# value of 90 seconds
# [*proxy_set_header*] - Array of vhost headers to set
# [*fastcgi*] - location of fastcgi (host:port)
# [*fastcgi_param*] - Set additional custom fastcgi_params
# [*fastcgi_params*] - optional alternative fastcgi_params file to use
# [*fastcgi_script*] - optional SCRIPT_FILE parameter
# [*fastcgi_split_path*] - Allows settings of fastcgi_split_path_info so
@ -81,6 +82,10 @@
# [*priority*] - Location priority. Default: 500. User priority
# 401-499, 501-599. If the priority is higher than the default priority,
# the location will be defined after root, or before root.
# [*mp4*] - Indicates whether or not this loation can be
# used for mp4 streaming. Default: false
# [*flv*] - Indicates whether or not this loation can be
# used for flv streaming. Default: false
#
#
# Actions:
@ -109,6 +114,17 @@
# vhost => 'test2.local',
# location_cfg_append => $my_config,
# }
#
# Add Custom fastcgi_params
# nginx::resource::location { 'test2.local-bob':
# ensure => present,
# www_root => '/var/www/bob',
# location => '/bob',
# vhost => 'test2.local',
# fastcgi_param => {
# 'APP_ENV' => 'local',
# }
# }
define nginx::resource::location (
$ensure = present,
@ -127,6 +143,7 @@ define nginx::resource::location (
$proxy_connect_timeout = $nginx::config::proxy_connect_timeout,
$proxy_set_header = $nginx::config::proxy_set_header,
$fastcgi = undef,
$fastcgi_param = undef,
$fastcgi_params = "${nginx::config::conf_dir}/fastcgi_params",
$fastcgi_script = undef,
$fastcgi_split_path = undef,
@ -154,7 +171,9 @@ define nginx::resource::location (
$auth_basic = undef,
$auth_basic_user_file = undef,
$rewrite_rules = [],
$priority = 500
$priority = 500,
$mp4 = false,
$flv = false,
) {
include nginx::params
@ -190,6 +209,9 @@ define nginx::resource::location (
if ($fastcgi != undef) {
validate_string($fastcgi)
}
if ($fastcgi_param != undef) {
validate_hash($fastcgi_param)
}
validate_string($fastcgi_params)
if ($fastcgi_script != undef) {
validate_string($fastcgi_script)
@ -283,7 +305,7 @@ define nginx::resource::location (
$config_file = "${nginx::config::conf_dir}/sites-available/${vhost_sanitized}.conf"
$location_sanitized_tmp = regsubst($location, '\/', '_', 'G')
$location_sanitized = regsubst($location_sanitized_tmp, "\\\\", '_', 'G')
$location_sanitized = regsubst($location_sanitized_tmp, '\\\\', '_', 'G')
## Check for various error conditions
if ($vhost == undef) {
@ -297,6 +319,10 @@ define nginx::resource::location (
}
# Use proxy, fastcgi or uwsgi template if $proxy is defined, otherwise use directory template.
# fastcgi_script is deprecated
if ($fastcgi_script != undef) {
warning('The $fastcgi_script parameter is deprecated; please use $fastcgi_param instead to define custom fastcgi_params!')
}
if ($proxy != undef) {
$content_real = template('nginx/vhost/locations/proxy.erb')
} elsif ($location_alias != undef) {
@ -334,7 +360,7 @@ define nginx::resource::location (
if ($ssl_only != true) {
$tmpFile=md5("${vhost_sanitized}-${priority}-${location_sanitized}")
concat::fragment { "${tmpFile}":
concat::fragment { $tmpFile:
ensure => present,
target => $config_file,
content => join([
@ -342,7 +368,7 @@ define nginx::resource::location (
$content_real,
template('nginx/vhost/location_footer.erb')
], ''),
order => "${priority}",
order => "${priority}", #lint:ignore:only_variable_string waiting on https://github.com/puppetlabs/puppetlabs-concat/commit/f70881fbfd01c404616e9e4139d98dad78d5a918
}
}
@ -351,7 +377,7 @@ define nginx::resource::location (
$ssl_priority = $priority + 300
$sslTmpFile=md5("${vhost_sanitized}-${ssl_priority}-${location_sanitized}-ssl")
concat::fragment {"${sslTmpFile}":
concat::fragment { $sslTmpFile:
ensure => present,
target => $config_file,
content => join([
@ -359,7 +385,7 @@ define nginx::resource::location (
$content_real,
template('nginx/vhost/location_footer.erb')
], ''),
order => "${ssl_priority}",
order => "${ssl_priority}", #lint:ignore:only_variable_string waiting on https://github.com/puppetlabs/puppetlabs-concat/commit/f70881fbfd01c404616e9e4139d98dad78d5a918
}
}

View file

@ -30,7 +30,7 @@
#
# Sample Hiera usage:
#
# nginx::maps:
# nginx::string_mappings:
# client_network:
# ensure: present
# hostnames: true
@ -60,6 +60,11 @@ define nginx::resource::map (
include nginx::params
$root_group = $nginx::params::root_group
$ensure_real = $ensure ? {
'absent' => absent,
default => 'file',
}
File {
owner => 'root',
group => $root_group,
@ -67,10 +72,7 @@ define nginx::resource::map (
}
file { "${nginx::config::conf_dir}/conf.d/${name}-map.conf":
ensure => $ensure ? {
'absent' => absent,
default => 'file',
},
ensure => $ensure_real,
content => template('nginx/conf.d/map.erb'),
notify => Class['nginx::service'],
}

View file

@ -57,6 +57,11 @@ define nginx::resource::upstream (
include nginx::params
$root_group = $nginx::params::root_group
$ensure_real = $ensure ? {
'absent' => absent,
default => present,
}
Concat {
owner => 'root',
group => $root_group,
@ -64,18 +69,14 @@ define nginx::resource::upstream (
}
concat { "${nginx::config::conf_dir}/conf.d/${name}-upstream.conf":
ensure => $ensure ? {
'absent' => absent,
'file' => present,
default => present,
},
notify => Class['nginx::service'],
ensure => $ensure_real,
notify => Class['nginx::service'],
}
# Uses: $name, $upstream_cfg_prepend
concat::fragment { "${name}_upstream_header":
target => "${nginx::config::conf_dir}/conf.d/${name}-upstream.conf",
order => 10,
order => '10',
content => template('nginx/conf.d/upstream_header.erb'),
}
@ -83,7 +84,7 @@ define nginx::resource::upstream (
# Uses: $members, $upstream_fail_timeout
concat::fragment { "${name}_upstream_members":
target => "${nginx::config::conf_dir}/conf.d/${name}-upstream.conf",
order => 50,
order => '50',
content => template('nginx/conf.d/upstream_members.erb'),
}
} else {
@ -93,7 +94,7 @@ define nginx::resource::upstream (
concat::fragment { "${name}_upstream_footer":
target => "${nginx::config::conf_dir}/conf.d/${name}-upstream.conf",
order => 90,
order => '90',
content => "}\n",
}
}

View file

@ -442,7 +442,7 @@ define nginx::resource::vhost (
# Add IPv6 Logic Check - Nginx service will not start if ipv6 is enabled
# and support does not exist for it in the kernel.
if ($ipv6_enable == true) and (!$ipaddress6) {
if ($ipv6_enable == true) and (!$::ipaddress6) {
warning('nginx: IPv6 support is not enabled or configured properly')
}

View file

@ -26,66 +26,66 @@ describe 'nginx::config' do
}
end
it { should contain_class("nginx::params") }
it { is_expected.to contain_class("nginx::params") }
it { should contain_file("/etc/nginx").only_with(
it { is_expected.to contain_file("/etc/nginx").only_with(
:path => "/etc/nginx",
:ensure => 'directory',
:owner => 'root',
:group => 'root',
:mode => '0644'
)}
it { should contain_file("/etc/nginx/conf.d").only_with(
it { is_expected.to contain_file("/etc/nginx/conf.d").only_with(
:path => '/etc/nginx/conf.d',
:ensure => 'directory',
:owner => 'root',
:group => 'root',
:mode => '0644'
)}
it { should contain_file("/etc/nginx/conf.mail.d").only_with(
it { is_expected.to contain_file("/etc/nginx/conf.mail.d").only_with(
:path => '/etc/nginx/conf.mail.d',
:ensure => 'directory',
:owner => 'root',
:group => 'root',
:mode => '0644'
)}
it { should contain_file("/etc/nginx/conf.d/vhost_autogen.conf").with_ensure('absent') }
it { should contain_file("/etc/nginx/conf.mail.d/vhost_autogen.conf").with_ensure('absent') }
it { should contain_file("/var/nginx").with(
it { is_expected.to contain_file("/etc/nginx/conf.d/vhost_autogen.conf").with_ensure('absent') }
it { is_expected.to contain_file("/etc/nginx/conf.mail.d/vhost_autogen.conf").with_ensure('absent') }
it { is_expected.to contain_file("/var/nginx").with(
:ensure => 'directory',
:owner => 'root',
:group => 'root',
:mode => '0644'
)}
it { should contain_file("/var/nginx/client_body_temp").with(
it { is_expected.to contain_file("/var/nginx/client_body_temp").with(
:ensure => 'directory',
:group => 'root',
:mode => '0644'
)}
it { should contain_file("/var/nginx/proxy_temp").with(
it { is_expected.to contain_file("/var/nginx/proxy_temp").with(
:ensure => 'directory',
:group => 'root',
:mode => '0644'
)}
it { should contain_file('/etc/nginx/sites-enabled/default').with_ensure('absent') }
it { should contain_file("/etc/nginx/nginx.conf").with(
it { is_expected.to contain_file('/etc/nginx/sites-enabled/default').with_ensure('absent') }
it { is_expected.to contain_file("/etc/nginx/nginx.conf").with(
:ensure => 'file',
:owner => 'root',
:group => 'root',
:mode => '0644'
)}
it { should contain_file("/etc/nginx/conf.d/proxy.conf").with(
it { is_expected.to contain_file("/etc/nginx/conf.d/proxy.conf").with(
:ensure => 'file',
:owner => 'root',
:group => 'root',
:mode => '0644'
)}
it { should contain_file("/tmp/nginx.d").with(
it { is_expected.to contain_file("/tmp/nginx.d").with(
:ensure => 'absent',
:purge => true,
:recurse => true
)}
it { should contain_file("/tmp/nginx.mail.d").with(
it { is_expected.to contain_file("/tmp/nginx.mail.d").with(
:ensure => 'absent',
:purge => true,
:recurse => true
@ -108,9 +108,9 @@ describe 'nginx::config' do
:operatingsystem => facts[:operatingsystem],
}
end
it { should contain_file("/var/nginx/client_body_temp").with(:owner => 'www-data')}
it { should contain_file("/var/nginx/proxy_temp").with(:owner => 'www-data')}
it { should contain_file("/etc/nginx/nginx.conf").with_content %r{^user www-data;}}
it { is_expected.to contain_file("/var/nginx/client_body_temp").with(:owner => 'www-data')}
it { is_expected.to contain_file("/var/nginx/proxy_temp").with(:owner => 'www-data')}
it { is_expected.to contain_file("/etc/nginx/nginx.conf").with_content %r{^user www-data;}}
end
end
end
@ -137,9 +137,9 @@ describe 'nginx::config' do
:operatingsystem => facts[:operatingsystem],
}
end
it { should contain_file("/var/nginx/client_body_temp").with(:owner => 'nginx')}
it { should contain_file("/var/nginx/proxy_temp").with(:owner => 'nginx')}
it { should contain_file("/etc/nginx/nginx.conf").with_content %r{^user nginx;}}
it { is_expected.to contain_file("/var/nginx/client_body_temp").with(:owner => 'nginx')}
it { is_expected.to contain_file("/var/nginx/proxy_temp").with(:owner => 'nginx')}
it { is_expected.to contain_file("/etc/nginx/nginx.conf").with_content %r{^user nginx;}}
end
end
end
@ -250,11 +250,11 @@ describe 'nginx::config' do
context "when #{param[:attr]} is #{param[:value]}" do
let :params do { param[:attr].to_sym => param[:value] } end
it { should contain_file("/etc/nginx/nginx.conf").with_mode('0644') }
it { is_expected.to contain_file("/etc/nginx/nginx.conf").with_mode('0644') }
it param[:title] do
verify_contents(subject, "/etc/nginx/nginx.conf", Array(param[:match]))
Array(param[:notmatch]).each do |item|
should contain_file("/etc/nginx/nginx.conf").without_content(item)
is_expected.to contain_file("/etc/nginx/nginx.conf").without_content(item)
end
end
end
@ -306,11 +306,11 @@ describe 'nginx::config' do
context "when #{param[:attr]} is #{param[:value]}" do
let :params do { param[:attr].to_sym => param[:value] } end
it { should contain_file("/etc/nginx/conf.d/proxy.conf").with_mode('0644') }
it { is_expected.to contain_file("/etc/nginx/conf.d/proxy.conf").with_mode('0644') }
it param[:title] do
verify_contents(subject, "/etc/nginx/conf.d/proxy.conf", Array(param[:match]))
Array(param[:notmatch]).each do |item|
should contain_file("/etc/nginx/conf.d/proxy.conf").without_content(item)
is_expected.to contain_file("/etc/nginx/conf.d/proxy.conf").without_content(item)
end
end
end
@ -319,7 +319,7 @@ describe 'nginx::config' do
context "when confd_purge true" do
let(:params) {{:confd_purge => true}}
it { should contain_file('/etc/nginx/conf.d').with(
it { is_expected.to contain_file('/etc/nginx/conf.d').with(
:purge => true,
:recurse => true
)}
@ -327,7 +327,7 @@ describe 'nginx::config' do
context "when confd_purge false" do
let(:params) {{:confd_purge => false}}
it { should contain_file('/etc/nginx/conf.d').without([
it { is_expected.to contain_file('/etc/nginx/conf.d').without([
'ignore',
'purge',
'recurse'
@ -336,11 +336,11 @@ describe 'nginx::config' do
context "when vhost_purge true" do
let(:params) {{:vhost_purge => true}}
it { should contain_file('/etc/nginx/sites-available').with(
it { is_expected.to contain_file('/etc/nginx/sites-available').with(
:purge => true,
:recurse => true
)}
it { should contain_file('/etc/nginx/sites-enabled').with(
it { is_expected.to contain_file('/etc/nginx/sites-enabled').with(
:purge => true,
:recurse => true
)}
@ -348,12 +348,12 @@ describe 'nginx::config' do
context "when vhost_purge false" do
let(:params) {{:vhost_purge => false}}
it { should contain_file('/etc/nginx/sites-available').without([
it { is_expected.to contain_file('/etc/nginx/sites-available').without([
'ignore',
'purge',
'recurse'
])}
it { should contain_file('/etc/nginx/sites-enabled').without([
it { is_expected.to contain_file('/etc/nginx/sites-enabled').without([
'ignore',
'purge',
'recurse'

View file

@ -11,20 +11,20 @@ describe 'nginx' do
end
shared_examples "a Linux OS" do
it { should compile.with_all_deps }
it { should contain_class('nginx') }
it { should contain_anchor('nginx::begin') }
it { should contain_nginx__package.that_requires('Anchor[nginx::begin]') }
it { should contain_nginx__config.that_requires('Class[nginx::package]') }
it { should contain_nginx__service.that_subscribes_to('Anchor[nginx::begin]') }
it { should contain_nginx__service.that_subscribes_to('Class[nginx::package]') }
it { should contain_nginx__service.that_subscribes_to('Class[nginx::config]') }
it { should contain_anchor('nginx::end').that_requires('Class[nginx::service]') }
it { should contain_class("nginx::params") }
it { should contain_nginx__resource__upstream("upstream1") }
it { should contain_nginx__resource__vhost("test2.local") }
it { should contain_nginx__resource__location("test2.local") }
it { should contain_nginx__resource__mailhost("smtp.test2.local") }
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('nginx') }
it { is_expected.to contain_anchor('nginx::begin') }
it { is_expected.to contain_nginx__package.that_requires('Anchor[nginx::begin]') }
it { is_expected.to contain_nginx__config.that_requires('Class[nginx::package]') }
it { is_expected.to contain_nginx__service.that_subscribes_to('Anchor[nginx::begin]') }
it { is_expected.to contain_nginx__service.that_subscribes_to('Class[nginx::package]') }
it { is_expected.to contain_nginx__service.that_subscribes_to('Class[nginx::config]') }
it { is_expected.to contain_anchor('nginx::end').that_requires('Class[nginx::service]') }
it { is_expected.to contain_class("nginx::params") }
it { is_expected.to contain_nginx__resource__upstream("upstream1") }
it { is_expected.to contain_nginx__resource__vhost("test2.local") }
it { is_expected.to contain_nginx__resource__location("test2.local") }
it { is_expected.to contain_nginx__resource__mailhost("smtp.test2.local") }
end
context "Debian OS" do
@ -34,6 +34,7 @@ describe 'nginx' do
:operatingsystem => 'Debian',
:osfamily => 'Debian',
:lsbdistcodename => 'precise',
:lsbdistid => 'Debian',
}
end
end

View file

@ -6,8 +6,8 @@ describe 'nginx::package' do
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'RedHat' }}
context "using defaults" do
it { should contain_package('nginx') }
it { should contain_yumrepo('nginx-release').with(
it { is_expected.to contain_package('nginx') }
it { is_expected.to contain_yumrepo('nginx-release').with(
'baseurl' => 'http://nginx.org/packages/rhel/6/$basearch/',
'descr' => 'nginx repo',
'enabled' => '1',
@ -15,25 +15,25 @@ describe 'nginx::package' do
'priority' => '1',
'gpgkey' => 'http://nginx.org/keys/nginx_signing.key'
)}
it { should contain_file('/etc/yum.repos.d/nginx-release.repo') }
it { should contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::redhat]') }
it { should contain_anchor('nginx::package::end').that_requires('Class[nginx::package::redhat]') }
it { is_expected.to contain_file('/etc/yum.repos.d/nginx-release.repo') }
it { is_expected.to contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::redhat]') }
it { is_expected.to contain_anchor('nginx::package::end').that_requires('Class[nginx::package::redhat]') }
end
context "manage_repo => false" do
let(:params) {{ :manage_repo => false }}
it { should contain_package('nginx') }
it { should_not contain_yumrepo('nginx-release') }
it { should_not contain_file('/etc/yum.repos.d/nginx-release.repo') }
it { is_expected.to contain_package('nginx') }
it { is_expected.not_to contain_yumrepo('nginx-release') }
it { is_expected.not_to contain_file('/etc/yum.repos.d/nginx-release.repo') }
end
context "lsbmajdistrelease = 5" do
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'RedHat', :lsbmajdistrelease => 5 }}
it { should contain_package('nginx') }
it { should contain_yumrepo('nginx-release').with(
it { is_expected.to contain_package('nginx') }
it { is_expected.to contain_yumrepo('nginx-release').with(
'baseurl' => 'http://nginx.org/packages/rhel/5/$basearch/'
)}
it { should contain_file('/etc/yum.repos.d/nginx-release.repo') }
it { is_expected.to contain_file('/etc/yum.repos.d/nginx-release.repo') }
end
describe 'installs the requested package version' do
@ -41,34 +41,39 @@ describe 'nginx::package' do
let(:params) {{ :package_ensure => '3.0.0' }}
it 'installs 3.0.0 exactly' do
should contain_package('nginx').with({
is_expected.to contain_package('nginx').with({
'ensure' => '3.0.0'
})
end
end
end
shared_examples 'debian' do |operatingsystem, lsbdistcodename|
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'Debian', :lsbdistcodename => lsbdistcodename }}
shared_examples 'debian' do |operatingsystem, lsbdistcodename, lsbdistid|
let(:facts) {{
:operatingsystem => operatingsystem,
:osfamily => 'Debian',
:lsbdistcodename => lsbdistcodename,
:lsbdistid => lsbdistid
}}
context "using defaults" do
it { should contain_package('nginx') }
it { should_not contain_package('passenger') }
it { should contain_apt__source('nginx').with(
it { is_expected.to contain_package('nginx') }
it { is_expected.not_to contain_package('passenger') }
it { is_expected.to contain_apt__source('nginx').with(
'location' => "http://nginx.org/packages/#{operatingsystem}",
'repos' => 'nginx',
'key' => '7BD9BF62',
'key_source' => 'http://nginx.org/keys/nginx_signing.key'
)}
it { should contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::debian]') }
it { should contain_anchor('nginx::package::end').that_requires('Class[nginx::package::debian]') }
it { is_expected.to contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::debian]') }
it { is_expected.to contain_anchor('nginx::package::end').that_requires('Class[nginx::package::debian]') }
end
context "package_source => 'passenger'" do
let(:params) {{ :package_source => 'passenger' }}
it { should contain_package('nginx') }
it { should contain_package('passenger') }
it { should contain_apt__source('nginx').with(
it { is_expected.to contain_package('nginx') }
it { is_expected.to contain_package('passenger') }
it { is_expected.to contain_apt__source('nginx').with(
'location' => 'https://oss-binaries.phusionpassenger.com/apt/passenger',
'repos' => "main",
'key' => '561F9B9CAC40B2F7',
@ -78,9 +83,9 @@ describe 'nginx::package' do
context "manage_repo => false" do
let(:params) {{ :manage_repo => false }}
it { should contain_package('nginx') }
it { should_not contain_apt__source('nginx') }
it { should_not contain_package('passenger') }
it { is_expected.to contain_package('nginx') }
it { is_expected.not_to contain_apt__source('nginx') }
it { is_expected.not_to contain_package('passenger') }
end
end
@ -89,10 +94,10 @@ describe 'nginx::package' do
[
'nginx',
].each do |package|
it { should contain_package("#{package}") }
it { is_expected.to contain_package("#{package}") }
end
it { should contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::suse]') }
it { should contain_anchor('nginx::package::end').that_requires('Class[nginx::package::suse]') }
it { is_expected.to contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::suse]') }
it { is_expected.to contain_anchor('nginx::package::end').that_requires('Class[nginx::package::suse]') }
end
@ -105,8 +110,8 @@ describe 'nginx::package' do
end
context 'debian' do
it_behaves_like 'debian', 'debian', 'wheezy'
it_behaves_like 'debian', 'ubuntu', 'precise'
it_behaves_like 'debian', 'debian', 'wheezy', 'debian'
it_behaves_like 'debian', 'ubuntu', 'precise', 'ubuntu'
end
context 'suse' do
@ -116,8 +121,8 @@ describe 'nginx::package' do
context 'amazon with facter < 1.7.2' do
let(:facts) {{ :operatingsystem => 'Amazon', :osfamily => 'Linux' }}
it { should contain_package('nginx') }
it { should contain_yumrepo('nginx-release').with(
it { is_expected.to contain_package('nginx') }
it { is_expected.to contain_yumrepo('nginx-release').with(
'baseurl' => 'http://nginx.org/packages/rhel/6/$basearch/',
'descr' => 'nginx repo',
'enabled' => '1',
@ -125,18 +130,18 @@ describe 'nginx::package' do
'priority' => '1',
'gpgkey' => 'http://nginx.org/keys/nginx_signing.key'
)}
it { should contain_file('/etc/yum.repos.d/nginx-release.repo') }
it { should contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::redhat]') }
it { should contain_anchor('nginx::package::end').that_requires('Class[nginx::package::redhat]') }
it { is_expected.to contain_file('/etc/yum.repos.d/nginx-release.repo') }
it { is_expected.to contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::redhat]') }
it { is_expected.to contain_anchor('nginx::package::end').that_requires('Class[nginx::package::redhat]') }
end
context 'fedora' do
# fedora is identical to the rest of osfamily RedHat except for not
# including nginx-release
let(:facts) {{ :operatingsystem => 'Fedora', :osfamily => 'RedHat', :lsbmajdistrelease => 6 }}
it { should contain_package('nginx') }
it { should_not contain_yumrepo('nginx-release') }
it { should_not contain_file('/etc/yum.repos.d/nginx-release.repo') }
it { is_expected.to contain_package('nginx') }
it { is_expected.not_to contain_yumrepo('nginx-release') }
it { is_expected.not_to contain_file('/etc/yum.repos.d/nginx-release.repo') }
end
context 'other' do

View file

@ -7,9 +7,9 @@ describe 'nginx::params' do
:operatingsystem => 'debian',
} end
it { should contain_nginx__params }
it { should have_class_count(1) } #only nginx::params itself
it { should have_resource_count(0) } #params class should never declare resources
it { is_expected.to contain_nginx__params }
it { is_expected.to have_class_count(1) } #only nginx::params itself
it { is_expected.to have_resource_count(0) } #params class should never declare resources
end
end

View file

@ -14,24 +14,32 @@ describe 'nginx::service' do
context "using default parameters" do
it { should contain_service('nginx').with(
it { is_expected.to contain_service('nginx').with(
:ensure => 'running',
:enable => true,
:hasstatus => true,
:hasrestart => true
)}
it { should contain_service('nginx').without_restart }
it { is_expected.to contain_service('nginx').without_restart }
end
describe "when configtest_enable => true" do
let(:params) {{ :configtest_enable => true, :service_restart => '/etc/init.d/nginx configtest && /etc/init.d/nginx restart'}}
it { should contain_service('nginx').with_restart('/etc/init.d/nginx configtest && /etc/init.d/nginx restart') }
let :params do {
:configtest_enable => true,
:service_restart => '/etc/init.d/nginx configtest && /etc/init.d/nginx restart',
:service_ensure => 'running',
} end
it { is_expected.to contain_service('nginx').with_restart('/etc/init.d/nginx configtest && /etc/init.d/nginx restart') }
context "when service_restart => 'a restart command'" do
let(:params) {{ :configtest_enable => true, :service_restart => 'a restart command' }}
it { should contain_service('nginx').with_restart('a restart command') }
let :params do {
:configtest_enable => true,
:service_restart => 'a restart command',
:service_ensure => 'running',
} end
it { is_expected.to contain_service('nginx').with_restart('a restart command') }
end
end

View file

@ -35,7 +35,7 @@ describe 'nginx::resource::geo' do
describe 'basic assumptions' do
let :params do default_params end
it { should contain_file("/etc/nginx/conf.d/#{title}-geo.conf").with(
it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-geo.conf").with(
{
'owner' => 'root',
'group' => 'root',
@ -105,11 +105,11 @@ describe 'nginx::resource::geo' do
context "when #{param[:attr]} is #{param[:value]}" do
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
it { should contain_file("/etc/nginx/conf.d/#{title}-geo.conf").with_mode('0644') }
it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-geo.conf").with_mode('0644') }
it param[:title] do
verify_contents(subject, "/etc/nginx/conf.d/#{title}-geo.conf", Array(param[:match]))
Array(param[:notmatch]).each do |item|
should contain_file("/etc/nginx/conf.d/#{title}-geo.conf").without_content(item)
is_expected.to contain_file("/etc/nginx/conf.d/#{title}-geo.conf").without_content(item)
end
end
end
@ -122,7 +122,7 @@ describe 'nginx::resource::geo' do
}
) end
it { should contain_file("/etc/nginx/conf.d/#{title}-geo.conf").with_ensure('absent') }
it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-geo.conf").with_ensure('absent') }
end
end
end

View file

@ -26,13 +26,12 @@ describe 'nginx::resource::location' do
:vhost => 'vhost1',
} end
it { should contain_class("nginx::params") }
it { should contain_class("nginx::config") }
it { should contain_concat__fragment("f25e14942fb58942ee13b1465a4e1719").with_content(/location rspec-test/) }
it { should_not contain_file('/etc/nginx/fastcgi_params') }
it { should_not contain_file('/etc/nginx/uwsgi_params') }
it { should_not contain_concat__fragment("vhost1-800-rspec-test-ssl") }
it { should_not contain_file("/etc/nginx/rspec-test_htpasswd") }
it { is_expected.to contain_class("nginx::params") }
it { is_expected.to contain_class("nginx::config") }
it { is_expected.to contain_concat__fragment("f25e14942fb58942ee13b1465a4e1719").with_content(/location rspec-test/) }
it { is_expected.not_to contain_file('/etc/nginx/fastcgi_params') }
it { is_expected.not_to contain_concat__fragment("vhost1-800-rspec-test-ssl") }
it { is_expected.not_to contain_file("/etc/nginx/rspec-test_htpasswd") }
end
describe "vhost/location_header template content" do
@ -55,6 +54,30 @@ describe 'nginx::resource::location' do
:value => true,
:match => ' internal;'
},
{
:title => 'should not set mp4',
:attr => 'mp4',
:value => false,
:notmatch => /mp4;/
},
{
:title => 'should set mp4',
:attr => 'mp4',
:value => true,
:match => ' mp4;'
},
{
:title => 'should not set flv',
:attr => 'flv',
:value => false,
:notmatch => /flv;/
},
{
:title => 'should set flv',
:attr => 'flv',
:value => true,
:match => ' flv;'
},
{
:title => 'should set location_allow',
:attr => 'location_allow',
@ -118,21 +141,21 @@ describe 'nginx::resource::location' do
let :default_params do { :location => 'location', :proxy => 'proxy_value', :vhost => 'vhost1' } end
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
it { should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")) }
it { is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")) }
it param[:title] do
fragment = Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")
matches = Array(param[:match])
if matches.all? { |m| m.is_a? Regexp }
matches.each { |item| should contain_concat__fragment(fragment).with_content(item) }
matches.each { |item| is_expected.to contain_concat__fragment(fragment).with_content(item) }
else
lines = subject.resource('concat::fragment', fragment).send(:parameters)[:content].split("\n")
(lines & matches).should == matches
expect(lines & matches).to eq(matches)
end
Array(param[:notmatch]).each do |item|
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).without_content(item)
is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).without_content(item)
end
end
end
@ -186,28 +209,28 @@ describe 'nginx::resource::location' do
let :default_params do { :location => 'location', :proxy => 'proxy_value', :vhost => 'vhost1' } end
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
it { should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")) }
it { is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")) }
it param[:title] do
fragment = Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")
matches = Array(param[:match])
if matches.all? { |m| m.is_a? Regexp }
matches.each { |item| should contain_concat__fragment(fragment).with_content(item) }
matches.each { |item| is_expected.to contain_concat__fragment(fragment).with_content(item) }
else
lines = subject.resource('concat::fragment', fragment).send(:parameters)[:content].split("\n")
(lines & matches).should == matches
expect(lines & matches).to eq(matches)
end
Array(param[:notmatch]).each do |item|
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).without_content(item)
is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).without_content(item)
end
end
it "should end with a closing brace" do
fragment = Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")
content = subject.resource('concat::fragment', fragment).send(:parameters)[:content]
(content.split("\n").reject {|l| l =~ /^(\s*#|$)/ }.last).strip.should == '}'
expect((content.split("\n").reject {|l| l =~ /^(\s*#|$)/ }.last).strip).to eq('}')
end
end
end
@ -220,27 +243,27 @@ describe 'nginx::resource::location' do
context "when location_alias is 'value'" do
let :params do default_params end
it { should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")) }
it { is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")) }
it "should set alias" do
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")).
is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")).
with_content(/^[ ]+alias\s+value;/)
end
end
context "when autoindex is 'on'" do
let :params do default_params.merge({ :autoindex => 'on' }) end
it { should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")) }
it { is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")) }
it "should set autoindex" do
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")).
is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")).
with_content(/^[ ]+autoindex\s+on;/)
end
end
context "when autoindex is not set" do
let :params do default_params end
it { should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")) }
it { is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")) }
it "should not set autoindex" do
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")).
is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")).
without_content(/^[ ]+autoindex[^;]+;/)
end
end
@ -310,20 +333,20 @@ describe 'nginx::resource::location' do
context "when #{param[:attr]} is #{param[:value]}" do
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
it { should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")) }
it { is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")) }
it param[:title] do
fragment = Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")
matches = Array(param[:match])
if matches.all? { |m| m.is_a? Regexp }
matches.each { |item| should contain_concat__fragment(fragment).with_content(item) }
matches.each { |item| is_expected.to contain_concat__fragment(fragment).with_content(item) }
else
lines = subject.resource('concat::fragment', fragment).send(:parameters)[:content].split("\n")
(lines & matches).should == matches
expect(lines & matches).to eq(matches)
end
Array(param[:notmatch]).each do |item|
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).without_content(item)
is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).without_content(item)
end
end
end
@ -331,18 +354,18 @@ describe 'nginx::resource::location' do
context "when autoindex is 'on'" do
let :params do default_params.merge({ :autoindex => 'on' }) end
it { should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")) }
it { is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")) }
it "should set autoindex" do
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")).
is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")).
with_content(/^[ ]+autoindex\s+on;/)
end
end
context "when autoindex is not set" do
let :params do default_params end
it { should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")) }
it { is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")) }
it "should not set autoindex" do
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")).
is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")).
without_content(/^[ ]+autoindex[^;]+;/)
end
end
@ -371,20 +394,20 @@ describe 'nginx::resource::location' do
let :default_params do { :location => 'location', :location_custom_cfg => {'test1'=>'value1'}, :vhost => 'vhost1' } end
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
it { should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")) }
it { is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")) }
it param[:title] do
fragment = Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")
matches = Array(param[:match])
if matches.all? { |m| m.is_a? Regexp }
matches.each { |item| should contain_concat__fragment(fragment).with_content(item) }
matches.each { |item| is_expected.to contain_concat__fragment(fragment).with_content(item) }
else
lines = subject.resource('concat::fragment', fragment).send(:parameters)[:content].split("\n")
(lines & matches).should == matches
expect(lines & matches).to eq(matches)
end
Array(param[:notmatch]).each do |item|
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).without_content(item)
is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).without_content(item)
end
end
end
@ -435,20 +458,20 @@ describe 'nginx::resource::location' do
context "when #{param[:attr]} is #{param[:value]}" do
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
it { should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")) }
it { is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")) }
it param[:title] do
fragment = Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")
matches = Array(param[:match])
if matches.all? { |m| m.is_a? Regexp }
matches.each { |item| should contain_concat__fragment(fragment).with_content(item) }
matches.each { |item| is_expected.to contain_concat__fragment(fragment).with_content(item) }
else
lines = subject.resource('concat::fragment', fragment).send(:parameters)[:content].split("\n")
(lines & matches).should == matches
expect(lines & matches).to eq(matches)
end
Array(param[:notmatch]).each do |item|
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).without_content(item)
is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).without_content(item)
end
end
end
@ -456,21 +479,47 @@ describe 'nginx::resource::location' do
context "when fastcgi_script is 'value'" do
let :params do default_params.merge({ :fastcgi_script => 'value' }) end
it { should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")) }
it { is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")) }
it "should set fastcgi_script" do
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).
is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).
with_content(%r|^[ ]+fastcgi_param\s+SCRIPT_FILENAME\s+value;|)
end
end
context "when fastcgi_script is not set" do
let :params do default_params end
it { should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")) }
it { is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")) }
it "should not set fastcgi_script" do
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).
is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).
without_content(/^[ ]+fastcgi_param\s+SCRIPT_FILENAME\s+.+?;/)
end
end
context "when fastcgi_param is {'CUSTOM_PARAM' => 'value'}" do
let :params do default_params.merge({ :fastcgi_param => {'CUSTOM_PARAM' => 'value', 'CUSTOM_PARAM2' => 'value2'} }) end
it "should set fastcgi_param" do
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).
with_content(%r|fastcgi_param\s+CUSTOM_PARAM\s+value;|).
with_content(%r|fastcgi_param\s+CUSTOM_PARAM2\s+value2;|)
end
it "should add comment # Enable custom fastcgi_params" do
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).
with_content(%r|# Enable custom fastcgi_params\s+|)
end
end
context "when fastcgi_param is not set" do
let :params do default_params end
it "should not set fastcgi_param" do
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).
without_content(/fastcgi_param\s+CUSTOM_PARAM\s+.+?;/).
without_content(/fastcgi_param\s+CUSTOM_PARAM2\s+.+?;/)
end
it "should not add comment # Enable custom fastcgi_params" do
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).
without_content(/# Enable custom fastcgi_params\s+/)
end
end
end
describe "vhost_location_uwsgi template content" do
@ -539,13 +588,25 @@ describe 'nginx::resource::location' do
:value => 'value',
:match => /^[ ]+proxy_cache\s+value;/,
},
{
:title => 'should not set proxy_cache_valid',
:attr => 'proxy_cache_valid',
:value => false,
:notmatch => /proxy_cache_valid\b/
},
{
:title => 'should set proxy_cache_valid',
:attr => 'proxy_cache_valid',
:value => 'value',
:match => /^[ ]+proxy_cache_valid\s+value;/,
},
{
:title => 'should not set proxy_cache',
:attr => 'proxy_cache',
:value => false,
:notmatch => /proxy_cache\b/
},
{
{
:title => 'should set proxy_pass',
:attr => 'proxy',
:value => 'value',
@ -615,20 +676,20 @@ describe 'nginx::resource::location' do
let :default_params do { :location => 'location', :proxy => 'proxy_value', :vhost => 'vhost1' } end
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
it { should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")) }
it { is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")) }
it param[:title] do
fragment = Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")
matches = Array(param[:match])
if matches.all? { |m| m.is_a? Regexp }
matches.each { |item| should contain_concat__fragment(fragment).with_content(item) }
matches.each { |item| is_expected.to contain_concat__fragment(fragment).with_content(item) }
else
lines = subject.resource('concat::fragment', fragment).send(:parameters)[:content].split("\n")
(lines & matches).should == matches
expect(lines & matches).to eq(matches)
end
Array(param[:notmatch]).each do |item|
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).without_content(item)
is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).without_content(item)
end
end
end
@ -643,14 +704,14 @@ describe 'nginx::resource::location' do
:proxy_cache_valid => '10m',
} end
it { should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")).with_content(/proxy_cache_valid 10m;/) }
it { is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-location")).with_content(/proxy_cache_valid 10m;/) }
end
end
describe "vhost_location_stub_status template content" do
let :params do { :location => 'location', :stub_status => true, :vhost => 'vhost1' } end
it do
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).
is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).
with_content(/stub_status\s+on/)
end
end
@ -659,7 +720,7 @@ describe 'nginx::resource::location' do
context 'when fastcgi => "localhost:9000"' do
let :params do { :fastcgi => 'localhost:9000', :vhost => 'vhost1' } end
it { should contain_file('/etc/nginx/fastcgi_params').with_mode('0770') }
it { is_expected.to contain_file('/etc/nginx/fastcgi_params').with_mode('0770') }
end
context 'when uwsgi => "uwsgi_upstream"' do
@ -671,31 +732,31 @@ describe 'nginx::resource::location' do
context 'when ssl_only => true' do
let :params do { :ssl_only => true, :vhost => 'vhost1', :www_root => '/', } end
it { should_not contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-rspec-test")) }
it { is_expected.not_to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-rspec-test")) }
end
context 'when ssl_only => false' do
let :params do { :ssl_only => false, :vhost => 'vhost1', :www_root => '/', } end
it { should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-rspec-test")) }
it { is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-rspec-test")) }
end
context 'when ssl => true' do
let :params do { :ssl => true, :vhost => 'vhost1', :www_root => '/', } end
it { should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-800-rspec-test-ssl")) }
it { is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-800-rspec-test-ssl")) }
end
context 'when ssl => false' do
let :params do { :ssl => false, :vhost => 'vhost1', :www_root => '/', } end
it { should_not contain_concat__fragment(Digest::MD5.hexdigest("vhost1-800-rspec-test-ssl")) }
it { is_expected.not_to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-800-rspec-test-ssl")) }
end
context 'when auth_basic_user_file => true' do
let :params do { :auth_basic_user_file => '/path/to/file', :vhost => 'vhost1', :www_root => '/', } end
it { should contain_file("/etc/nginx/rspec-test_htpasswd") }
it { is_expected.to contain_file("/etc/nginx/rspec-test_htpasswd") }
end
context 'when ensure => absent' do
@ -707,7 +768,7 @@ describe 'nginx::resource::location' do
:auth_basic_user_file => '/path/to/file',
} end
it { should contain_file("/etc/nginx/rspec-test_htpasswd").with_ensure('absent') }
it { is_expected.to contain_file("/etc/nginx/rspec-test_htpasswd").with_ensure('absent') }
end
context "vhost missing" do
@ -715,7 +776,7 @@ describe 'nginx::resource::location' do
:www_root => '/',
} end
it { expect { should contain_class('nginx::resource::location') }.to raise_error(Puppet::Error, /Cannot create a location reference without attaching to a virtual host/) }
it { expect { is_expected.to contain_class('nginx::resource::location') }.to raise_error(Puppet::Error, /Cannot create a location reference without attaching to a virtual host/) }
end
context "location type missing" do
@ -723,7 +784,11 @@ describe 'nginx::resource::location' do
:vhost => 'vhost1',
} end
<<<<<<< HEAD
it { expect { should contain_class('nginx::resource::location') }.to raise_error(Puppet::Error, /Cannot create a location reference without a www_root, proxy, location_alias, fastcgi, uwsgi, stub_status, or location_custom_cfg defined/) }
=======
it { expect { is_expected.to contain_class('nginx::resource::location') }.to raise_error(Puppet::Error, /Cannot create a location reference without a www_root, proxy, location_alias, fastcgi, stub_status, or location_custom_cfg defined/) }
>>>>>>> a5592d4303cc43ed1e516a7beb91616b0e9fbe43
end
context "www_root and proxy are set" do
@ -733,7 +798,7 @@ describe 'nginx::resource::location' do
:proxy => 'http://localhost:8000/uri/',
} end
it { expect { should contain_class('nginx::resource::location') }.to raise_error(Puppet::Error, /Cannot define both directory and proxy in a virtual host/) }
it { expect { is_expected.to contain_class('nginx::resource::location') }.to raise_error(Puppet::Error, /Cannot define both directory and proxy in a virtual host/) }
end
context 'when vhost name is sanitized' do
@ -744,8 +809,8 @@ describe 'nginx::resource::location' do
:ssl => true,
} end
it { should contain_concat__fragment(Digest::MD5.hexdigest("www_rspec-vhost_com-500-www.rspec-location.com")).with_target('/etc/nginx/sites-available/www_rspec-vhost_com.conf') }
it { should contain_concat__fragment(Digest::MD5.hexdigest("www_rspec-vhost_com-800-www.rspec-location.com-ssl")).with_target('/etc/nginx/sites-available/www_rspec-vhost_com.conf') }
it { is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("www_rspec-vhost_com-500-www.rspec-location.com")).with_target('/etc/nginx/sites-available/www_rspec-vhost_com.conf') }
it { is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("www_rspec-vhost_com-800-www.rspec-location.com-ssl")).with_target('/etc/nginx/sites-available/www_rspec-vhost_com.conf') }
end
end
end

View file

@ -27,14 +27,14 @@ describe 'nginx::resource::mailhost' do
describe 'basic assumptions' do
let :params do default_params end
it { should contain_class("nginx::config") }
it { should contain_concat("/etc/nginx/conf.mail.d/#{title}.conf").with({
it { is_expected.to contain_class("nginx::config") }
it { is_expected.to contain_concat("/etc/nginx/conf.mail.d/#{title}.conf").with({
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
})}
it { should contain_concat__fragment("#{title}-header") }
it { should_not contain_concat__fragment("#{title}-ssl") }
it { is_expected.to contain_concat__fragment("#{title}-header") }
it { is_expected.not_to contain_concat__fragment("#{title}-ssl") }
end
describe "mailhost template content" do
@ -139,12 +139,12 @@ describe 'nginx::resource::mailhost' do
} end
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
it { should contain_concat__fragment("#{title}-header") }
it { is_expected.to contain_concat__fragment("#{title}-header") }
it param[:title] do
lines = subject.resource('concat::fragment', "#{title}-header").send(:parameters)[:content].split("\n")
(lines & Array(param[:match])).should == Array(param[:match])
expect(lines & Array(param[:match])).to eq(Array(param[:match]))
Array(param[:notmatch]).each do |item|
should contain_concat__fragment("#{title}-header").without_content(item)
is_expected.to contain_concat__fragment("#{title}-header").without_content(item)
end
end
end
@ -193,12 +193,12 @@ describe 'nginx::resource::mailhost' do
} end
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
it { should contain_concat__fragment("#{title}-header") }
it { is_expected.to contain_concat__fragment("#{title}-header") }
it param[:title] do
lines = subject.resource('concat::fragment', "#{title}-header").send(:parameters)[:content].split("\n")
(lines & Array(param[:match])).should == Array(param[:match])
expect(lines & Array(param[:match])).to eq(Array(param[:match]))
Array(param[:notmatch]).each do |item|
should contain_concat__fragment("#{title}-header").without_content(item)
is_expected.to contain_concat__fragment("#{title}-header").without_content(item)
end
end
end
@ -290,12 +290,12 @@ describe 'nginx::resource::mailhost' do
} end
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
it { should contain_concat__fragment("#{title}-ssl") }
it { is_expected.to contain_concat__fragment("#{title}-ssl") }
it param[:title] do
lines = subject.resource('concat::fragment', "#{title}-ssl").send(:parameters)[:content].split("\n")
(lines & Array(param[:match])).should == Array(param[:match])
expect(lines & Array(param[:match])).to eq(Array(param[:match]))
Array(param[:notmatch]).each do |item|
should contain_concat__fragment("#{title}-ssl").without_content(item)
is_expected.to contain_concat__fragment("#{title}-ssl").without_content(item)
end
end
end
@ -309,7 +309,7 @@ describe 'nginx::resource::mailhost' do
:ssl_key => 'key',
}) end
it { expect { should contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
it { expect { is_expected.to contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
end
context "SSL key missing and ssl => true" do
@ -318,7 +318,7 @@ describe 'nginx::resource::mailhost' do
:ssl_cert => 'cert',
}) end
it { expect { should contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
it { expect { is_expected.to contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
end
context "SSL cert missing and starttls => 'on'" do
@ -327,7 +327,7 @@ describe 'nginx::resource::mailhost' do
:ssl_key => 'key',
}) end
it { expect { should contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
it { expect { is_expected.to contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
end
context "SSL key missing and starttls => 'on'" do
@ -336,7 +336,7 @@ describe 'nginx::resource::mailhost' do
:ssl_cert => 'cert',
}) end
it { expect { should contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
it { expect { is_expected.to contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
end
context "SSL cert missing and starttls => 'only'" do
@ -345,7 +345,7 @@ describe 'nginx::resource::mailhost' do
:ssl_key => 'key',
}) end
it { expect { should contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
it { expect { is_expected.to contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
end
context "SSL key missing and starttls => 'only'" do
@ -354,7 +354,7 @@ describe 'nginx::resource::mailhost' do
:ssl_cert => 'cert',
}) end
it { expect { should contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
it { expect { is_expected.to contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
end
context 'when listen_port != ssl_port' do
@ -363,7 +363,7 @@ describe 'nginx::resource::mailhost' do
:ssl_port => 443,
}) end
it { should contain_concat__fragment("#{title}-header") }
it { is_expected.to contain_concat__fragment("#{title}-header") }
end
context 'when listen_port == ssl_port' do
@ -372,7 +372,7 @@ describe 'nginx::resource::mailhost' do
:ssl_port => 80,
}) end
it { should_not contain_concat__fragment("#{title}-header") }
it { is_expected.not_to contain_concat__fragment("#{title}-header") }
end
context 'when ssl => true' do
@ -383,8 +383,8 @@ describe 'nginx::resource::mailhost' do
:ssl_cert => 'dummy.cert',
}) end
it { should contain_concat__fragment("#{title}-header") }
it { should contain_concat__fragment("#{title}-ssl") }
it { is_expected.to contain_concat__fragment("#{title}-header") }
it { is_expected.to contain_concat__fragment("#{title}-ssl") }
end
context 'when ssl => false' do
@ -393,8 +393,8 @@ describe 'nginx::resource::mailhost' do
:ssl => false,
}) end
it { should contain_concat__fragment("#{title}-header") }
it { should_not contain_concat__fragment("#{title}-ssl") }
it { is_expected.to contain_concat__fragment("#{title}-header") }
it { is_expected.not_to contain_concat__fragment("#{title}-ssl") }
end
end
end

View file

@ -35,7 +35,7 @@ describe 'nginx::resource::map' do
describe 'basic assumptions' do
let :params do default_params end
it { should contain_file("/etc/nginx/conf.d/#{title}-map.conf").with(
it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-map.conf").with(
{
'owner' => 'root',
'group' => 'root',
@ -78,11 +78,11 @@ describe 'nginx::resource::map' do
context "when #{param[:attr]} is #{param[:value]}" do
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
it { should contain_file("/etc/nginx/conf.d/#{title}-map.conf").with_mode('0644') }
it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-map.conf").with_mode('0644') }
it param[:title] do
verify_contents(subject, "/etc/nginx/conf.d/#{title}-map.conf", Array(param[:match]))
Array(param[:notmatch]).each do |item|
should contain_file("/etc/nginx/conf.d/#{title}-map.conf").without_content(item)
is_expected.to contain_file("/etc/nginx/conf.d/#{title}-map.conf").without_content(item)
end
end
end
@ -95,7 +95,7 @@ describe 'nginx::resource::map' do
}
) end
it { should contain_file("/etc/nginx/conf.d/#{title}-map.conf").with_ensure('absent') }
it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-map.conf").with_ensure('absent') }
end
end
end

View file

@ -39,13 +39,13 @@ describe 'nginx::resource::upstream' do
describe 'basic assumptions' do
let :params do default_params end
it { should contain_class("nginx::params") }
it { should contain_class('concat::setup') }
it { should contain_file("/etc/nginx/conf.d/#{title}-upstream.conf") }
it { should contain_concat__fragment("#{title}_upstream_header").with_content(/upstream #{title}/) }
it { is_expected.to contain_class("nginx::params") }
it { is_expected.to contain_class('concat::setup') }
it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-upstream.conf") }
it { is_expected.to contain_concat__fragment("#{title}_upstream_header").with_content(/upstream #{title}/) }
it {
should contain_concat__fragment("#{title}_upstream_header").with(
is_expected.to contain_concat__fragment("#{title}_upstream_header").with(
{
'target' => "/etc/nginx/conf.d/#{title}-upstream.conf",
'order' => 10,
@ -53,7 +53,7 @@ describe 'nginx::resource::upstream' do
)}
it {
should contain_concat__fragment("#{title}_upstream_members").with(
is_expected.to contain_concat__fragment("#{title}_upstream_members").with(
{
'target' => "/etc/nginx/conf.d/#{title}-upstream.conf",
'order' => 50,
@ -61,7 +61,7 @@ describe 'nginx::resource::upstream' do
)}
it {
should contain_concat__fragment("#{title}_upstream_footer").with(
is_expected.to contain_concat__fragment("#{title}_upstream_footer").with(
{
'target' => "/etc/nginx/conf.d/#{title}-upstream.conf",
'order' => 90,
@ -110,13 +110,13 @@ describe 'nginx::resource::upstream' do
context "when #{param[:attr]} is #{param[:value]}" do
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
it { should contain_file("/etc/nginx/conf.d/#{title}-upstream.conf").with_mode('0644') }
it { should contain_concat__fragment("#{title}_upstream_#{param[:fragment]}") }
it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-upstream.conf").with_mode('0644') }
it { is_expected.to contain_concat__fragment("#{title}_upstream_#{param[:fragment]}") }
it param[:title] do
lines = subject.resource('concat::fragment', "#{title}_upstream_#{param[:fragment]}").send(:parameters)[:content].split("\n")
(lines & Array(param[:match])).should == Array(param[:match])
expect(lines & Array(param[:match])).to eq(Array(param[:match]))
Array(param[:notmatch]).each do |item|
should contain_concat__fragment("#{title}_upstream_#{param[:fragment]}").without_content(item)
is_expected.to contain_concat__fragment("#{title}_upstream_#{param[:fragment]}").without_content(item)
end
end
end
@ -129,7 +129,7 @@ describe 'nginx::resource::upstream' do
}
) end
it { should contain_file("/etc/nginx/conf.d/#{title}-upstream.conf").with_ensure('absent') }
it { is_expected.to contain_file("/etc/nginx/conf.d/#{title}-upstream.conf").with_ensure('absent') }
end
end
end

View file

@ -28,20 +28,19 @@ describe 'nginx::resource::vhost' do
describe 'basic assumptions' do
let :params do default_params end
it { should contain_class("nginx::params") }
it { should contain_class("nginx::config") }
it { should contain_concat("/etc/nginx/sites-available/#{title}.conf").with({
it { is_expected.to contain_class("nginx::params") }
it { is_expected.to contain_class("nginx::config") }
it { is_expected.to contain_concat("/etc/nginx/sites-available/#{title}.conf").with({
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
})}
it { should contain_concat__fragment("#{title}-header").with_content(%r{access_log[ ]+/var/log/nginx/www\.rspec\.example\.com\.access\.log}) }
it { should contain_concat__fragment("#{title}-header").with_content(%r{error_log[ ]+/var/log/nginx/www\.rspec\.example\.com\.error\.log}) }
it { should contain_concat__fragment("#{title}-footer") }
it { should contain_nginx__resource__location("#{title}-default") }
it { should_not contain_file("/etc/nginx/fastcgi_params") }
it { should_not contain_file("/etc/nginx/uwsgi_params") }
it { should contain_file("#{title}.conf symlink").with({
it { is_expected.to contain_concat__fragment("#{title}-header").with_content(%r{access_log[ ]+/var/log/nginx/www\.rspec\.example\.com\.access\.log}) }
it { is_expected.to contain_concat__fragment("#{title}-header").with_content(%r{error_log[ ]+/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_params") }
it { is_expected.to contain_file("#{title}.conf symlink").with({
'ensure' => 'link',
'path' => "/etc/nginx/sites-enabled/#{title}.conf",
'target' => "/etc/nginx/sites-available/#{title}.conf"
@ -243,18 +242,18 @@ describe 'nginx::resource::vhost' do
context "when #{param[:attr]} is #{param[:value]}" do
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
it { should contain_concat__fragment("#{title}-header") }
it { is_expected.to contain_concat__fragment("#{title}-header") }
it param[:title] do
matches = Array(param[:match])
if matches.all? { |m| m.is_a? Regexp }
matches.each { |item| should contain_concat__fragment("#{title}-header").with_content(item) }
matches.each { |item| is_expected.to contain_concat__fragment("#{title}-header").with_content(item) }
else
lines = subject.resource('concat::fragment', "#{title}-header").send(:parameters)[:content].split("\n")
(lines & Array(param[:match])).should == Array(param[:match])
expect(lines & Array(param[:match])).to eq(Array(param[:match]))
end
Array(param[:notmatch]).each do |item|
should contain_concat__fragment("#{title}-header").without_content(item)
is_expected.to contain_concat__fragment("#{title}-header").without_content(item)
end
end
end
@ -308,18 +307,18 @@ describe 'nginx::resource::vhost' do
context "when #{param[:attr]} is #{param[:value]}" do
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
it { should contain_concat__fragment("#{title}-footer") }
it { is_expected.to contain_concat__fragment("#{title}-footer") }
it param[:title] do
matches = Array(param[:match])
if matches.all? { |m| m.is_a? Regexp }
matches.each { |item| should contain_concat__fragment("#{title}-footer").with_content(item) }
matches.each { |item| is_expected.to contain_concat__fragment("#{title}-footer").with_content(item) }
else
lines = subject.resource('concat::fragment', "#{title}-footer").send(:parameters)[:content].split("\n")
(lines & Array(param[:match])).should == Array(param[:match])
expect(lines & Array(param[:match])).to eq(Array(param[:match]))
end
Array(param[:notmatch]).each do |item|
should contain_concat__fragment("#{title}-footer").without_content(item)
is_expected.to contain_concat__fragment("#{title}-footer").without_content(item)
end
end
end
@ -539,18 +538,18 @@ describe 'nginx::resource::vhost' do
:ssl_key => 'dummy.key',
:ssl_cert => 'dummy.crt',
}) end
it { should contain_concat__fragment("#{title}-ssl-header") }
it { is_expected.to contain_concat__fragment("#{title}-ssl-header") }
it param[:title] do
matches = Array(param[:match])
if matches.all? { |m| m.is_a? Regexp }
matches.each { |item| should contain_concat__fragment("#{title}-ssl-header").with_content(item) }
matches.each { |item| is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(item) }
else
lines = subject.resource('concat::fragment', "#{title}-ssl-header").send(:parameters)[:content].split("\n")
(lines & Array(param[:match])).should == Array(param[:match])
expect(lines & Array(param[:match])).to eq(Array(param[:match]))
end
Array(param[:notmatch]).each do |item|
should contain_concat__fragment("#{title}-ssl-header").without_content(item)
is_expected.to contain_concat__fragment("#{title}-ssl-header").without_content(item)
end
end
end
@ -619,18 +618,18 @@ describe 'nginx::resource::vhost' do
:ssl_cert => 'dummy.crt',
}) end
it { should contain_concat__fragment("#{title}-ssl-footer") }
it { is_expected.to contain_concat__fragment("#{title}-ssl-footer") }
it param[:title] do
matches = Array(param[:match])
if matches.all? { |m| m.is_a? Regexp }
matches.each { |item| should contain_concat__fragment("#{title}-ssl-footer").with_content(item) }
matches.each { |item| is_expected.to contain_concat__fragment("#{title}-ssl-footer").with_content(item) }
else
lines = subject.resource('concat::fragment', "#{title}-ssl-footer").send(:parameters)[:content].split("\n")
(lines & Array(param[:match])).should == Array(param[:match])
expect(lines & Array(param[:match])).to eq(Array(param[:match]))
end
Array(param[:notmatch]).each do |item|
should contain_concat__fragment("#{title}-ssl-footer").without_content(item)
is_expected.to contain_concat__fragment("#{title}-ssl-footer").without_content(item)
end
end
end
@ -652,7 +651,7 @@ describe 'nginx::resource::vhost' do
end
it "should set the server_name of the rewrite server stanza to the first server_name with 'www.' stripped" do
should contain_concat__fragment("#{title}-ssl-header").with_content(/^[ ]+server_name\s+foo.com;/)
is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(/^[ ]+server_name\s+foo.com;/)
end
end
@ -667,20 +666,20 @@ describe 'nginx::resource::vhost' do
end
it "should set the server_name of the rewrite server stanza to the first server_name with 'www.' stripped" do
should contain_concat__fragment("#{title}-header").with_content(/^[ ]+server_name\s+foo.com;/)
is_expected.to contain_concat__fragment("#{title}-header").with_content(/^[ ]+server_name\s+foo.com;/)
end
end
context "SSL cert missing" do
let(:params) {{ :ssl => true, :ssl_key => 'key' }}
it { expect { should contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error) }
it { expect { is_expected.to contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error) }
end
context "SSL key missing" do
let(:params) {{ :ssl => true, :ssl_cert => 'cert' }}
it { expect { should contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error) }
it { expect { is_expected.to contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error) }
end
context 'when use_default_location => true' do
@ -688,7 +687,7 @@ describe 'nginx::resource::vhost' do
:use_default_location => true,
}) end
it { should contain_nginx__resource__location("#{title}-default") }
it { is_expected.to contain_nginx__resource__location("#{title}-default") }
end
context 'when use_default_location => false' do
@ -696,7 +695,7 @@ describe 'nginx::resource::vhost' do
:use_default_location => false,
}) end
it { should_not contain_nginx__resource__location("#{title}-default") }
it { is_expected.not_to contain_nginx__resource__location("#{title}-default") }
end
context 'when location_cfg_prepend => { key => value }' do
@ -704,7 +703,7 @@ describe 'nginx::resource::vhost' do
:location_cfg_prepend => { 'key' => 'value' },
}) end
it { should contain_nginx__resource__location("#{title}-default").with_location_cfg_prepend({ 'key' => 'value' }) }
it { is_expected.to contain_nginx__resource__location("#{title}-default").with_location_cfg_prepend({ 'key' => 'value' }) }
end
context "when location_raw_prepend => [ 'foo;' ]" do
@ -712,7 +711,7 @@ describe 'nginx::resource::vhost' do
:location_raw_prepend => [ 'foo;' ],
}) end
it { should contain_nginx__resource__location("#{title}-default").with_raw_prepend([ 'foo;' ]) }
it { is_expected.to contain_nginx__resource__location("#{title}-default").with_raw_prepend([ 'foo;' ]) }
end
context "when location_raw_append => [ 'foo;' ]" do
@ -720,7 +719,7 @@ describe 'nginx::resource::vhost' do
:location_raw_append => [ 'foo;' ],
}) end
it { should contain_nginx__resource__location("#{title}-default").with_raw_append([ 'foo;' ]) }
it { is_expected.to contain_nginx__resource__location("#{title}-default").with_raw_append([ 'foo;' ]) }
end
context 'when location_cfg_append => { key => value }' do
@ -728,7 +727,7 @@ describe 'nginx::resource::vhost' do
:location_cfg_append => { 'key' => 'value' },
}) end
it { should contain_nginx__resource__location("#{title}-default").with_location_cfg_append({ 'key' => 'value' }) }
it { is_expected.to contain_nginx__resource__location("#{title}-default").with_location_cfg_append({ 'key' => 'value' }) }
end
context 'when fastcgi => "localhost:9000"' do
@ -736,7 +735,7 @@ describe 'nginx::resource::vhost' do
:fastcgi => 'localhost:9000',
}) end
it { should contain_file('/etc/nginx/fastcgi_params').with_mode('0770') }
it { is_expected.to contain_file('/etc/nginx/fastcgi_params').with_mode('0770') }
end
context 'when uwsgi => "uwsgi_upstream"' do
@ -754,8 +753,8 @@ describe 'nginx::resource::vhost' do
:ssl_port => 80,
}) end
it { should_not contain_concat__fragment("#{title}-header") }
it { should_not contain_concat__fragment("#{title}-footer") }
it { is_expected.not_to contain_concat__fragment("#{title}-header") }
it { is_expected.not_to contain_concat__fragment("#{title}-footer") }
end
context 'when listen_port != ssl_port' do
@ -764,8 +763,8 @@ describe 'nginx::resource::vhost' do
:ssl_port => 443,
}) end
it { should contain_concat__fragment("#{title}-header") }
it { should contain_concat__fragment("#{title}-footer") }
it { is_expected.to contain_concat__fragment("#{title}-header") }
it { is_expected.to contain_concat__fragment("#{title}-footer") }
end
context 'when ensure => absent' do
@ -776,8 +775,8 @@ describe 'nginx::resource::vhost' do
:ssl_cert => 'dummy.cert',
}) end
it { should contain_nginx__resource__location("#{title}-default").with_ensure('absent') }
it { should contain_file("#{title}.conf symlink").with_ensure('absent') }
it { is_expected.to contain_nginx__resource__location("#{title}-default").with_ensure('absent') }
it { is_expected.to contain_file("#{title}.conf symlink").with_ensure('absent') }
end
context 'when ssl => true and ssl_port == listen_port' do
@ -789,12 +788,12 @@ describe 'nginx::resource::vhost' do
:ssl_cert => 'dummy.cert',
}) end
it { should contain_nginx__resource__location("#{title}-default").with_ssl_only(true) }
it { should contain_concat__fragment("#{title}-ssl-header").with_content(%r{access_log[ ]+/var/log/nginx/ssl-www\.rspec\.example\.com\.access\.log}) }
it { should contain_concat__fragment("#{title}-ssl-header").with_content(%r{error_log[ ]+/var/log/nginx/ssl-www\.rspec\.example\.com\.error\.log}) }
it { should contain_concat__fragment("#{title}-ssl-footer") }
it { should contain_file("/etc/nginx/#{title}.crt") }
it { should contain_file("/etc/nginx/#{title}.key") }
it { is_expected.to contain_nginx__resource__location("#{title}-default").with_ssl_only(true) }
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{access_log[ ]+/var/log/nginx/ssl-www\.rspec\.example\.com\.access\.log}) }
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{error_log[ ]+/var/log/nginx/ssl-www\.rspec\.example\.com\.error\.log}) }
it { is_expected.to contain_concat__fragment("#{title}-ssl-footer") }
it { is_expected.to contain_file("/etc/nginx/#{title}.crt") }
it { is_expected.to contain_file("/etc/nginx/#{title}.key") }
end
context 'when passenger_cgi_param is set' do
@ -802,9 +801,9 @@ describe 'nginx::resource::vhost' do
:passenger_cgi_param => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'test3' => 'test value 3' }
}) end
it { should contain_concat__fragment("#{title}-header").with_content( /passenger_set_cgi_param test1 test value 1;/ ) }
it { should contain_concat__fragment("#{title}-header").with_content( /passenger_set_cgi_param test2 test value 2;/ ) }
it { should contain_concat__fragment("#{title}-header").with_content( /passenger_set_cgi_param test3 test value 3;/ ) }
it { is_expected.to contain_concat__fragment("#{title}-header").with_content( /passenger_set_cgi_param test1 test value 1;/ ) }
it { is_expected.to contain_concat__fragment("#{title}-header").with_content( /passenger_set_cgi_param test2 test value 2;/ ) }
it { is_expected.to contain_concat__fragment("#{title}-header").with_content( /passenger_set_cgi_param test3 test value 3;/ ) }
end
context 'when passenger_cgi_param is set and ssl => true' do
@ -815,16 +814,16 @@ describe 'nginx::resource::vhost' do
:ssl_cert => 'dummy.cert',
}) end
it { should contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_set_cgi_param test1 test value 1;/ ) }
it { should contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_set_cgi_param test2 test value 2;/ ) }
it { should contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_set_cgi_param test3 test value 3;/ ) }
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_set_cgi_param test1 test value 1;/ ) }
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_set_cgi_param test2 test value 2;/ ) }
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_set_cgi_param test3 test value 3;/ ) }
end
context 'when vhost name is sanitized' do
let :title do 'www rspec-vhost com' end
let :params do default_params end
it { should contain_concat('/etc/nginx/sites-available/www_rspec-vhost_com.conf') }
it { is_expected.to contain_concat('/etc/nginx/sites-available/www_rspec-vhost_com.conf') }
end
end
end

View file

@ -1,16 +1,16 @@
# This file managed by puppet on host <%= @fqdn %>
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
@ -21,7 +21,7 @@ fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param HTTPS $https;
fastcgi_param HTTPS $https;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

View file

@ -2,6 +2,12 @@
<% if @internal -%>
internal;
<% end -%>
<% if @mp4 -%>
mp4;
<% end -%>
<% if @flv -%>
flv;
<% end -%>
<% if @location_allow -%>
<%- @location_allow.each do |allow_rule| -%>
allow <%= allow_rule %>;

View file

@ -12,3 +12,9 @@
<% if defined? @fastcgi_script %>
fastcgi_param SCRIPT_FILENAME <%= @fastcgi_script %>;
<% end -%>
<% if defined? @fastcgi_param %>
# Enable custom fastcgi_params
<% @fastcgi_param.each_pair do |key, val| -%>
fastcgi_param <%= key %> <%= val %>;
<% end -%>
<% end %>

View file

@ -1,5 +1,7 @@
<% if @proxy_cache -%>
proxy_cache <%= @proxy_cache %>;
<% end -%>
<% if @proxy_cache_valid -%>
proxy_cache_valid <%= @proxy_cache_valid %>;
<% end -%>
proxy_pass <%= @proxy %>;

View file

@ -77,7 +77,7 @@ server {
}
<% end -%>
<% if @index_files.count > 0 -%>
index <% Array(@index_files).each do |i| %> <%= i %><% end %>;
index <% Array(@index_files).each do |i| %> <%= i %><% end %>;
<% end -%>
<% if defined? @log_by_lua -%>
log_by_lua '<%= @log_by_lua %>';

12
tests/location_params.pp Normal file
View file

@ -0,0 +1,12 @@
include nginx
nginx::resource::location { 'www.test.com-params':
ensure => present,
location => '/some/url',
vhost => 'www.test.com',
fastcgi_param => {
'APP_ENV' => 'production',
'APP_VERSION' => '0.1.10',
'APP_SECRET' => 'hisfaihicasagfkjsa',
},
}

View file

@ -1,16 +1,16 @@
include nginx
nginx::resource::vhost { 'test.local test':
ensure => present,
ipv6_enable => true,
proxy => 'http://proxypass',
ensure => present,
ipv6_enable => true,
proxy => 'http://proxypass',
}
nginx::resource::vhost { 'test.local:8080':
ensure => present,
listen_port => 8080,
server_name => ['test.local test'],
ipv6_enable => true,
proxy => 'http://proxypass',
ensure => present,
listen_port => 8080,
server_name => ['test.local test'],
ipv6_enable => true,
proxy => 'http://proxypass',
}