forked from voxpupuli/puppet-nginx
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves voxpupuli#65
- Loading branch information
Matthew Haughton
committed
Nov 22, 2013
1 parent
5f31637
commit 179bdf9
Showing
10 changed files
with
2,113 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,296 @@ | ||
require 'spec_helper' | ||
describe 'nginx::config' do | ||
|
||
describe 'with defaults' do | ||
[ | ||
{ :osfamily => 'debian', :operatingsystem => 'debian', }, | ||
{ :osfamily => 'debian', :operatingsystem => 'ubuntu', }, | ||
{ :osfamily => 'redhat', :operatingsystem => 'fedora', }, | ||
{ :osfamily => 'redhat', :operatingsystem => 'rhel', }, | ||
{ :osfamily => 'redhat', :operatingsystem => 'redhat', }, | ||
{ :osfamily => 'redhat', :operatingsystem => 'centos', }, | ||
{ :osfamily => 'redhat', :operatingsystem => 'scientific', }, | ||
{ :osfamily => 'redhat', :operatingsystem => 'amazon', }, | ||
{ :osfamily => 'suse', :operatingsystem => 'suse', }, | ||
{ :osfamily => 'suse', :operatingsystem => 'opensuse', }, | ||
{ :osfamily => 'gentoo', :operatingsystem => 'gentoo', }, | ||
{ :osfamily => 'linux', :operatingsystem => 'gentoo', }, | ||
].each do |facts| | ||
|
||
context "when osfamily/operatingsystem is #{facts[:osfamily]}/#{facts[:operatingsystem]}" do | ||
|
||
let :facts do | ||
{ | ||
:osfamily => facts[:osfamily], | ||
:operatingsystem => facts[:operatingsystem], | ||
:kernel => 'linux', | ||
} | ||
end | ||
|
||
it { should include_class("nginx::params") } | ||
|
||
it { should contain_file("/etc/nginx").with( | ||
:ensure => 'directory', | ||
:owner => 'root', | ||
:group => 'root', | ||
:mode => '0644' | ||
)} | ||
it { should contain_file("/etc/nginx/conf.d").with( | ||
:ensure => 'directory', | ||
:owner => 'root', | ||
:group => 'root', | ||
:mode => '0644' | ||
)} | ||
it { should contain_file("/etc/nginx/conf.mail.d").with( | ||
:ensure => 'directory', | ||
:owner => 'root', | ||
:group => 'root', | ||
:mode => '0644' | ||
)} | ||
it { should contain_file("/var/nginx").with( | ||
:ensure => 'directory', | ||
:owner => 'root', | ||
:group => 'root', | ||
:mode => '0644' | ||
)} | ||
it { should contain_file("/var/nginx/client_body_temp").with( | ||
:ensure => 'directory', | ||
:group => 'root', | ||
:mode => '0644' | ||
)} | ||
it { should 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( | ||
:ensure => 'file', | ||
:owner => 'root', | ||
:group => 'root', | ||
:mode => '0644' | ||
)} | ||
it { should 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( | ||
:ensure => 'directory', | ||
:purge => true, | ||
:recurse => true, | ||
:owner => 'root', | ||
:group => 'root', | ||
:mode => '0644' | ||
)} | ||
it { should contain_file("/tmp/nginx.mail.d").with( | ||
:ensure => 'directory', | ||
:purge => true, | ||
:recurse => true, | ||
:owner => 'root', | ||
:group => 'root', | ||
:mode => '0644' | ||
)} | ||
end | ||
end | ||
end | ||
|
||
describe 'with defaults' do | ||
[ | ||
{ :osfamily => 'debian', :operatingsystem => 'debian', }, | ||
{ :osfamily => 'debian', :operatingsystem => 'ubuntu', }, | ||
].each do |facts| | ||
|
||
context "when osfamily/operatingsystem is #{facts[:osfamily]}/#{facts[:operatingsystem]}" do | ||
|
||
let :facts do | ||
{ | ||
:osfamily => facts[:osfamily], | ||
:operatingsystem => facts[:operatingsystem], | ||
:kernel => 'linux', | ||
} | ||
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;}} | ||
end | ||
end | ||
end | ||
|
||
describe 'with defaults' do | ||
[ | ||
{ :osfamily => 'redhat', :operatingsystem => 'fedora', }, | ||
{ :osfamily => 'redhat', :operatingsystem => 'rhel', }, | ||
{ :osfamily => 'redhat', :operatingsystem => 'redhat', }, | ||
{ :osfamily => 'redhat', :operatingsystem => 'centos', }, | ||
{ :osfamily => 'redhat', :operatingsystem => 'scientific', }, | ||
{ :osfamily => 'redhat', :operatingsystem => 'amazon', }, | ||
{ :osfamily => 'suse', :operatingsystem => 'suse', }, | ||
{ :osfamily => 'suse', :operatingsystem => 'opensuse', }, | ||
{ :osfamily => 'gentoo', :operatingsystem => 'gentoo', }, | ||
{ :osfamily => 'linux', :operatingsystem => 'gentoo', }, | ||
].each do |facts| | ||
|
||
context "when osfamily/operatingsystem is #{facts[:osfamily]}/#{facts[:operatingsystem]}" do | ||
|
||
let :facts do | ||
{ | ||
:osfamily => facts[:osfamily], | ||
:operatingsystem => facts[:operatingsystem], | ||
:kernel => 'linux', | ||
} | ||
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;}} | ||
end | ||
end | ||
end | ||
|
||
describe 'os-independent items' do | ||
|
||
let :facts do | ||
{ | ||
:osfamily => 'debian', | ||
:operatingsystem => 'debian', | ||
:kernel => 'linux', | ||
} | ||
end | ||
|
||
describe "nginx.conf template content" do | ||
[ | ||
{ | ||
:title => 'should set worker_processes', | ||
:attr => 'worker_processes', | ||
:value => '4', | ||
:match => 'worker_processes 4;', | ||
}, | ||
{ | ||
:title => 'should set error_log', | ||
:attr => 'nginx_error_log', | ||
:value => '/path/to/error.log', | ||
:match => 'error_log /path/to/error.log;', | ||
}, | ||
{ | ||
:title => 'should set worker_connections', | ||
:attr => 'worker_connections', | ||
:value => '100', | ||
:match => ' worker_connections 100;', | ||
}, | ||
{ | ||
:title => 'should set access_log', | ||
:attr => 'http_access_log', | ||
:value => '/path/to/access.log', | ||
:match => ' access_log /path/to/access.log;', | ||
}, | ||
{ | ||
:title => 'should set server_tokens', | ||
:attr => 'server_tokens', | ||
:value => 'on', | ||
:match => ' server_tokens on;', | ||
}, | ||
{ | ||
:title => 'should set proxy_cache_path', | ||
:attr => 'proxy_cache_path', | ||
:value => '/path/to/proxy.cache', | ||
:match => ' proxy_cache_path /path/to/proxy.cache levels=1 keys_zone=d2:100m max_size=500m inactive=20m;', | ||
}, | ||
{ | ||
:title => 'should not set proxy_cache_path', | ||
:attr => 'proxy_cache_path', | ||
:value => false, | ||
:notmatch => ' proxy_cache_path /path/to/proxy.cache levels=1 keys_zone=d2:100m max_size=500m inactive=20m;', | ||
}, | ||
{ | ||
:title => 'should contain ordered appended directives', | ||
:attr => 'http_cfg_append', | ||
:value => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' }, | ||
:match => [ | ||
' allow test value 3;', | ||
' test1 test value 1;', | ||
' test2 test value 2;', | ||
], | ||
}, | ||
].each do |param| | ||
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 param[:title] do | ||
verify_contents(subject, "/etc/nginx/nginx.conf", Array(param[:match])) | ||
lines = subject.resource('file', "/etc/nginx/nginx.conf").send(:parameters)[:content].split("\n") | ||
(Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe "proxy.conf template content" do | ||
[ | ||
{ | ||
:title => 'should set client_max_body_size', | ||
:attr => 'client_max_body_size', | ||
:value => '5m', | ||
:match => 'client_max_body_size 5m;', | ||
}, | ||
{ | ||
:title => 'should set proxy_buffers', | ||
:attr => 'proxy_buffers', | ||
:value => '50 5k', | ||
:match => 'proxy_buffers 50 5k;', | ||
}, | ||
{ | ||
:title => 'should set proxy_buffer_size', | ||
:attr => 'proxy_buffer_size', | ||
:value => '2k', | ||
:match => 'proxy_buffer_size 2k;', | ||
}, | ||
{ | ||
:title => 'should set proxy_http_version', | ||
:attr => 'proxy_http_version', | ||
:value => '1.1', | ||
:match => 'proxy_http_version 1.1;', | ||
}, | ||
{ | ||
:title => 'should contain ordered appended directives', | ||
:attr => 'proxy_set_header', | ||
:value => ['header1','header2'], | ||
:match => [ | ||
'proxy_set_header header1;', | ||
'proxy_set_header header2;', | ||
], | ||
}, | ||
].each do |param| | ||
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 param[:title] do | ||
verify_contents(subject, "/etc/nginx/conf.d/proxy.conf", Array(param[:match])) | ||
lines = subject.resource('file', "/etc/nginx/conf.d/proxy.conf").send(:parameters)[:content].split("\n") | ||
(Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty | ||
end | ||
end | ||
end | ||
end | ||
|
||
context "when confd_purge true" do | ||
let(:params) {{:confd_purge => true}} | ||
it { should contain_file('/etc/nginx/conf.d').with( | ||
:ignore => 'vhost_autogen.conf', | ||
:purge => true, | ||
:recurse => true | ||
)} | ||
end | ||
|
||
context "when confd_purge false" do | ||
let(:params) {{:confd_purge => false}} | ||
it { should contain_file('/etc/nginx/conf.d').without([ | ||
'ignore', | ||
'purge', | ||
'recurse' | ||
])} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,66 @@ | ||
require 'spec_helper' | ||
|
||
describe 'nginx' do | ||
|
||
shared_examples 'linux' do |operatingsystem, user| | ||
let(:facts) {{ :kernel => 'linux', :operatingsystem => operatingsystem, :osfamily => operatingsystem, :lsbdistcodename => 'precise' }} | ||
|
||
it { should contain_service('nginx').with( | ||
:ensure => 'running', | ||
:enable => true | ||
) } | ||
|
||
it { should contain_file('/var/nginx/client_body_temp').with_owner(user) } | ||
let :params do | ||
{ | ||
:nginx_upstreams => { 'upstream1' => { 'members' => ['localhost:3000']} }, | ||
:nginx_vhosts => { 'test2.local' => { 'www_root' => '/' } }, | ||
:nginx_locations => { 'test2.local' => { 'vhost' => 'test2.local', 'www_root' => '/'} } | ||
} | ||
end | ||
|
||
context "on a Debian OS" do | ||
let :facts do | ||
{ | ||
:kernel => 'linux', | ||
:operatingsystem => 'Debian', | ||
:osfamily => 'Debian', | ||
:lsbdistcodename => 'precise', | ||
} | ||
end | ||
|
||
context 'redhat' do | ||
it_behaves_like 'linux', 'redhat', 'nginx' | ||
it { should contain_nginx__package } | ||
it { should contain_nginx__config } | ||
it { should contain_nginx__service } | ||
it { should include_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") } | ||
end | ||
|
||
context 'debian' do | ||
it_behaves_like 'linux', 'debian', 'www-data' | ||
end | ||
context "on a RedHat OS" do | ||
let :facts do | ||
{ | ||
:kernel => 'linux', | ||
:operatingsystem => 'RedHat', | ||
:osfamily => 'RedHat', | ||
} | ||
end | ||
|
||
describe 'installs the requested package version' do | ||
let(:facts) {{ :kernel => 'linux', :operatingsystem => 'redhat', :osfamily => 'redhat' }} | ||
let(:params) {{ :package_ensure => '3.0.0' }} | ||
it { should contain_nginx__package } | ||
it { should contain_nginx__config } | ||
it { should contain_nginx__service } | ||
it { should include_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") } | ||
end | ||
|
||
it 'installs 3.0.0 exactly' do | ||
should contain_package('nginx').with({ | ||
'ensure' => '3.0.0' | ||
}) | ||
context "on a Suse OS" do | ||
let :facts do | ||
{ | ||
:kernel => 'linux', | ||
:operatingsystem => 'SuSE', | ||
:osfamily => 'Suse', | ||
} | ||
end | ||
end | ||
|
||
it { should contain_nginx__package } | ||
it { should contain_nginx__config } | ||
it { should contain_nginx__service } | ||
it { should include_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") } | ||
end | ||
end |
Oops, something went wrong.