spec: cleanup
* Removed some tests that no longer apply and/or are redundant * Only set OS facts when testing OS-specific behaviors. This simplifies the facts that must be set in the specs and saves running the same tests several times when the results wouldn't differ by OS anyway.
This commit is contained in:
parent
50c1e57c4c
commit
1898182c6d
11 changed files with 31 additions and 192 deletions
|
@ -1,31 +1,7 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
describe 'nginx::config' do
|
describe 'nginx::config' do
|
||||||
|
|
||||||
describe 'with defaults' do
|
context 'with defaults' do
|
||||||
[
|
|
||||||
{ :osfamily => 'Debian', :operatingsystem => 'Debian', },
|
|
||||||
{ :osfamily => 'Debian', :operatingsystem => 'Ubuntu', },
|
|
||||||
{ :osfamily => 'Redhat', :operatingsystem => 'Fedora', },
|
|
||||||
{ :osfamily => 'Redhat', :operatingsystem => 'RedHat', },
|
|
||||||
{ :osfamily => 'Redhat', :operatingsystem => 'OracleLinux', },
|
|
||||||
{ :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],
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
it { is_expected.to contain_file("/etc/nginx").only_with(
|
it { is_expected.to contain_file("/etc/nginx").only_with(
|
||||||
:path => "/etc/nginx",
|
:path => "/etc/nginx",
|
||||||
:ensure => 'directory',
|
:ensure => 'directory',
|
||||||
|
@ -88,68 +64,9 @@ describe 'nginx::config' do
|
||||||
:purge => true,
|
:purge => true,
|
||||||
:recurse => true
|
:recurse => true
|
||||||
)}
|
)}
|
||||||
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],
|
|
||||||
}
|
|
||||||
end
|
|
||||||
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
|
|
||||||
|
|
||||||
describe 'with defaults' do
|
|
||||||
[
|
|
||||||
{ :osfamily => 'RedHat', :operatingsystem => 'Fedora', },
|
|
||||||
{ :osfamily => 'RedHat', :operatingsystem => 'RedHat', },
|
|
||||||
{ :osfamily => 'RedHat', :operatingsystem => 'OracleLinux', },
|
|
||||||
{ :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],
|
|
||||||
}
|
|
||||||
end
|
|
||||||
it { is_expected.to contain_file("/var/nginx/client_body_temp").with(:owner => '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("/var/nginx/proxy_temp").with(:owner => 'nginx')}
|
||||||
it { is_expected.to contain_file("/etc/nginx/nginx.conf").with_content %r{^user nginx;}}
|
it { is_expected.to 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',
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "nginx.conf template content" do
|
describe "nginx.conf template content" do
|
||||||
[
|
[
|
||||||
|
@ -391,5 +308,16 @@ describe 'nginx::config' do
|
||||||
'recurse'
|
'recurse'
|
||||||
])}
|
])}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when daemon_user = www-data" do
|
||||||
|
let :params do
|
||||||
|
{
|
||||||
|
:daemon_user => 'www-data',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe 'nginx' do
|
describe 'nginx' do
|
||||||
|
let :facts do
|
||||||
|
{
|
||||||
|
:osfamily => 'Gentoo',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
let :params do
|
let :params do
|
||||||
{
|
{
|
||||||
:nginx_upstreams => { 'upstream1' => { 'members' => ['localhost:3000']} },
|
:nginx_upstreams => { 'upstream1' => { 'members' => ['localhost:3000']} },
|
||||||
|
@ -11,7 +17,7 @@ describe 'nginx' do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples "a Linux OS" do
|
describe "with defaults" do
|
||||||
it { is_expected.to compile.with_all_deps }
|
it { is_expected.to compile.with_all_deps }
|
||||||
it { is_expected.to contain_class('nginx') }
|
it { is_expected.to contain_class('nginx') }
|
||||||
it { is_expected.to contain_anchor('nginx::begin') }
|
it { is_expected.to contain_anchor('nginx::begin') }
|
||||||
|
@ -27,39 +33,4 @@ describe 'nginx' do
|
||||||
it { is_expected.to contain_nginx__resource__location("test2.local") }
|
it { is_expected.to contain_nginx__resource__location("test2.local") }
|
||||||
it { is_expected.to contain_nginx__resource__mailhost("smtp.test2.local") }
|
it { is_expected.to contain_nginx__resource__mailhost("smtp.test2.local") }
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Debian OS" do
|
|
||||||
it_behaves_like "a Linux OS" do
|
|
||||||
let :facts do
|
|
||||||
{
|
|
||||||
:operatingsystem => 'Debian',
|
|
||||||
:osfamily => 'Debian',
|
|
||||||
:lsbdistcodename => 'precise',
|
|
||||||
:lsbdistid => 'Debian',
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "RedHat OS" do
|
|
||||||
it_behaves_like "a Linux OS" do
|
|
||||||
let :facts do
|
|
||||||
{
|
|
||||||
:operatingsystem => 'RedHat',
|
|
||||||
:osfamily => 'RedHat',
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "Suse OS" do
|
|
||||||
it_behaves_like "a Linux OS" do
|
|
||||||
let :facts do
|
|
||||||
{
|
|
||||||
:operatingsystem => 'SuSE',
|
|
||||||
:osfamily => 'Suse',
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
||||||
describe 'nginx::package' do
|
describe 'nginx::package' do
|
||||||
|
|
||||||
shared_examples 'redhat' do |operatingsystem|
|
shared_examples 'redhat' do |operatingsystem|
|
||||||
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'RedHat' }}
|
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'RedHat', :operatingsystemmajrelease => '6' }}
|
||||||
context "using defaults" do
|
context "using defaults" do
|
||||||
it { is_expected.to contain_package('nginx') }
|
it { is_expected.to contain_package('nginx') }
|
||||||
it { is_expected.to contain_yumrepo('nginx-release').with(
|
it { is_expected.to contain_yumrepo('nginx-release').with(
|
||||||
|
@ -20,14 +20,15 @@ describe 'nginx::package' do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "manage_repo => false" do
|
context "manage_repo => false" do
|
||||||
|
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'RedHat', :operatingsystemmajrelease => '7' }}
|
||||||
let(:params) {{ :manage_repo => false }}
|
let(:params) {{ :manage_repo => false }}
|
||||||
it { is_expected.to contain_package('nginx') }
|
it { is_expected.to contain_package('nginx') }
|
||||||
it { is_expected.not_to contain_yumrepo('nginx-release') }
|
it { is_expected.not_to contain_yumrepo('nginx-release') }
|
||||||
it { is_expected.not_to contain_file('/etc/yum.repos.d/nginx-release.repo') }
|
it { is_expected.not_to contain_file('/etc/yum.repos.d/nginx-release.repo') }
|
||||||
end
|
end
|
||||||
|
|
||||||
context "lsbmajdistrelease = 5" do
|
context "operatingsystemmajrelease = 5" do
|
||||||
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'RedHat', :lsbmajdistrelease => 5 }}
|
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'RedHat', :operatingsystemmajrelease => '5' }}
|
||||||
it { is_expected.to contain_package('nginx') }
|
it { is_expected.to contain_package('nginx') }
|
||||||
it { is_expected.to contain_yumrepo('nginx-release').with(
|
it { is_expected.to contain_yumrepo('nginx-release').with(
|
||||||
'baseurl' => 'http://nginx.org/packages/rhel/5/$basearch/'
|
'baseurl' => 'http://nginx.org/packages/rhel/5/$basearch/'
|
||||||
|
@ -36,7 +37,7 @@ describe 'nginx::package' do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'installs the requested package version' do
|
describe 'installs the requested package version' do
|
||||||
let(:facts) {{ :operatingsystem => 'redhat', :osfamily => 'redhat' }}
|
let(:facts) {{ :operatingsystem => 'redhat', :osfamily => 'redhat', :operatingsystemmajrelease => '7'}}
|
||||||
let(:params) {{ :package_ensure => '3.0.0' }}
|
let(:params) {{ :package_ensure => '3.0.0' }}
|
||||||
|
|
||||||
it 'installs 3.0.0 exactly' do
|
it 'installs 3.0.0 exactly' do
|
||||||
|
@ -47,9 +48,10 @@ describe 'nginx::package' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples 'debian' do |operatingsystem, lsbdistcodename, lsbdistid|
|
shared_examples 'debian' do |operatingsystem, lsbdistcodename, lsbdistid, operatingsystemmajrelease|
|
||||||
let(:facts) {{
|
let(:facts) {{
|
||||||
:operatingsystem => operatingsystem,
|
:operatingsystem => operatingsystem,
|
||||||
|
:operatingsystemmajrelease => operatingsystemmajrelease,
|
||||||
:osfamily => 'Debian',
|
:osfamily => 'Debian',
|
||||||
:lsbdistcodename => lsbdistcodename,
|
:lsbdistcodename => lsbdistcodename,
|
||||||
:lsbdistid => lsbdistid
|
:lsbdistid => lsbdistid
|
||||||
|
@ -59,7 +61,7 @@ describe 'nginx::package' do
|
||||||
it { is_expected.to contain_package('nginx') }
|
it { is_expected.to contain_package('nginx') }
|
||||||
it { is_expected.not_to contain_package('passenger') }
|
it { is_expected.not_to contain_package('passenger') }
|
||||||
it { is_expected.to contain_apt__source('nginx').with(
|
it { is_expected.to contain_apt__source('nginx').with(
|
||||||
'location' => "http://nginx.org/packages/#{operatingsystem}",
|
'location' => "http://nginx.org/packages/#{operatingsystem.downcase}",
|
||||||
'repos' => 'nginx',
|
'repos' => 'nginx',
|
||||||
'key' => '7BD9BF62',
|
'key' => '7BD9BF62',
|
||||||
'key_source' => 'http://nginx.org/keys/nginx_signing.key'
|
'key_source' => 'http://nginx.org/keys/nginx_signing.key'
|
||||||
|
@ -88,36 +90,15 @@ describe 'nginx::package' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples 'suse' do |operatingsystem|
|
|
||||||
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'Suse'}}
|
|
||||||
[
|
|
||||||
'nginx',
|
|
||||||
].each do |package|
|
|
||||||
it { is_expected.to contain_package("#{package}") }
|
|
||||||
end
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
context 'redhat' do
|
context 'redhat' do
|
||||||
it_behaves_like 'redhat', 'centos'
|
it_behaves_like 'redhat', 'CentOS'
|
||||||
it_behaves_like 'redhat', 'rhel'
|
it_behaves_like 'redhat', 'RedHat'
|
||||||
it_behaves_like 'redhat', 'redhat'
|
|
||||||
it_behaves_like 'redhat', 'scientific'
|
|
||||||
it_behaves_like 'redhat', 'amazon'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'debian' do
|
context 'debian' do
|
||||||
it_behaves_like 'debian', 'debian', 'wheezy', 'debian'
|
it_behaves_like 'debian', 'Debian', 'wheezy', 'Debian', '6'
|
||||||
it_behaves_like 'debian', 'ubuntu', 'precise', 'ubuntu'
|
it_behaves_like 'debian', 'Ubuntu', 'precise', 'Ubuntu', '12.04'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'suse' do
|
|
||||||
it_behaves_like 'suse', 'opensuse'
|
|
||||||
it_behaves_like 'suse', 'suse'
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'amazon with facter < 1.7.2' do
|
context 'amazon with facter < 1.7.2' do
|
||||||
let(:facts) {{ :operatingsystem => 'Amazon', :osfamily => 'Linux' }}
|
let(:facts) {{ :operatingsystem => 'Amazon', :osfamily => 'Linux' }}
|
||||||
it { is_expected.to contain_package('nginx') }
|
it { is_expected.to contain_package('nginx') }
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
describe 'nginx::service' do
|
describe 'nginx::service' do
|
||||||
|
|
||||||
let :facts do {
|
|
||||||
:osfamily => 'Debian',
|
|
||||||
:operatingsystem => 'Debian',
|
|
||||||
} end
|
|
||||||
|
|
||||||
let :params do {
|
let :params do {
|
||||||
:configtest_enable => false,
|
:configtest_enable => false,
|
||||||
:service_restart => '/etc/init.d/nginx configtest && /etc/init.d/nginx restart',
|
:service_restart => '/etc/init.d/nginx configtest && /etc/init.d/nginx restart',
|
||||||
|
|
|
@ -17,13 +17,6 @@ describe 'nginx::resource::geo' do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
let :facts do
|
|
||||||
{
|
|
||||||
:osfamily => 'RedHat',
|
|
||||||
:operatingsystem => 'CentOS',
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
let :pre_condition do
|
let :pre_condition do
|
||||||
[
|
[
|
||||||
'include ::nginx::config',
|
'include ::nginx::config',
|
||||||
|
|
|
@ -5,12 +5,6 @@ describe 'nginx::resource::location' do
|
||||||
let :title do
|
let :title do
|
||||||
'rspec-test'
|
'rspec-test'
|
||||||
end
|
end
|
||||||
let :facts do
|
|
||||||
{
|
|
||||||
:osfamily => 'Debian',
|
|
||||||
:operatingsystem => 'Debian',
|
|
||||||
}
|
|
||||||
end
|
|
||||||
let :pre_condition do
|
let :pre_condition do
|
||||||
[
|
[
|
||||||
'include ::nginx::config',
|
'include ::nginx::config',
|
||||||
|
|
|
@ -6,8 +6,6 @@ describe 'nginx::resource::mailhost' do
|
||||||
end
|
end
|
||||||
let :facts do
|
let :facts do
|
||||||
{
|
{
|
||||||
:osfamily => 'Debian',
|
|
||||||
:operatingsystem => 'Debian',
|
|
||||||
:ipaddress6 => '::',
|
:ipaddress6 => '::',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,13 +17,6 @@ describe 'nginx::resource::map' do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
let :facts do
|
|
||||||
{
|
|
||||||
:osfamily => 'RedHat',
|
|
||||||
:operatingsystem => 'CentOS',
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
let :pre_condition do
|
let :pre_condition do
|
||||||
[
|
[
|
||||||
'include ::nginx::config',
|
'include ::nginx::config',
|
||||||
|
|
|
@ -17,14 +17,6 @@ describe 'nginx::resource::upstream' do
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
let :default_facts do
|
|
||||||
{
|
|
||||||
:osfamily => 'RedHat',
|
|
||||||
:operatingsystem => 'CentOS',
|
|
||||||
:concat_basedir => '/var/lib/puppet/concat'
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
let :pre_condition do
|
let :pre_condition do
|
||||||
[
|
[
|
||||||
'include ::nginx::config',
|
'include ::nginx::config',
|
||||||
|
@ -32,8 +24,6 @@ describe 'nginx::resource::upstream' do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'os-independent items' do
|
describe 'os-independent items' do
|
||||||
let :facts do default_facts end
|
|
||||||
|
|
||||||
describe 'basic assumptions' do
|
describe 'basic assumptions' do
|
||||||
let :params do default_params end
|
let :params do default_params end
|
||||||
|
|
||||||
|
@ -67,7 +57,6 @@ describe 'nginx::resource::upstream' do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "upstream.conf template content" do
|
describe "upstream.conf template content" do
|
||||||
let :facts do default_facts end
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
:title => 'should contain ordered prepended directives',
|
:title => 'should contain ordered prepended directives',
|
||||||
|
|
|
@ -12,8 +12,6 @@ describe 'nginx::resource::vhost' do
|
||||||
end
|
end
|
||||||
let :facts do
|
let :facts do
|
||||||
{
|
{
|
||||||
:osfamily => 'Debian',
|
|
||||||
:operatingsystem => 'debian',
|
|
||||||
:ipaddress6 => '::',
|
:ipaddress6 => '::',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,6 @@ require 'puppetlabs_spec_helper/module_spec_helper'
|
||||||
|
|
||||||
RSpec.configure do |c|
|
RSpec.configure do |c|
|
||||||
c.default_facts = {
|
c.default_facts = {
|
||||||
:kernel => 'Linux',
|
|
||||||
:concat_basedir => '/var/lib/puppet/concat',
|
:concat_basedir => '/var/lib/puppet/concat',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue