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'
|
||||
describe 'nginx::config' do
|
||||
|
||||
describe '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
|
||||
|
||||
context 'with defaults' do
|
||||
it { is_expected.to contain_file("/etc/nginx").only_with(
|
||||
:path => "/etc/nginx",
|
||||
:ensure => 'directory',
|
||||
|
@ -88,68 +64,9 @@ describe 'nginx::config' do
|
|||
:purge => 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/proxy_temp").with(:owner => '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
|
||||
[
|
||||
|
@ -391,5 +308,16 @@ describe 'nginx::config' do
|
|||
'recurse'
|
||||
])}
|
||||
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
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'nginx' do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Gentoo',
|
||||
}
|
||||
end
|
||||
|
||||
let :params do
|
||||
{
|
||||
:nginx_upstreams => { 'upstream1' => { 'members' => ['localhost:3000']} },
|
||||
|
@ -11,7 +17,7 @@ describe 'nginx' do
|
|||
}
|
||||
end
|
||||
|
||||
shared_examples "a Linux OS" do
|
||||
describe "with defaults" do
|
||||
it { is_expected.to compile.with_all_deps }
|
||||
it { is_expected.to contain_class('nginx') }
|
||||
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__mailhost("smtp.test2.local") }
|
||||
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
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
|||
describe 'nginx::package' do
|
||||
|
||||
shared_examples 'redhat' do |operatingsystem|
|
||||
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'RedHat' }}
|
||||
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'RedHat', :operatingsystemmajrelease => '6' }}
|
||||
context "using defaults" do
|
||||
it { is_expected.to contain_package('nginx') }
|
||||
it { is_expected.to contain_yumrepo('nginx-release').with(
|
||||
|
@ -20,14 +20,15 @@ describe 'nginx::package' do
|
|||
end
|
||||
|
||||
context "manage_repo => false" do
|
||||
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'RedHat', :operatingsystemmajrelease => '7' }}
|
||||
let(:params) {{ :manage_repo => false }}
|
||||
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 }}
|
||||
context "operatingsystemmajrelease = 5" do
|
||||
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'RedHat', :operatingsystemmajrelease => '5' }}
|
||||
it { is_expected.to contain_package('nginx') }
|
||||
it { is_expected.to contain_yumrepo('nginx-release').with(
|
||||
'baseurl' => 'http://nginx.org/packages/rhel/5/$basearch/'
|
||||
|
@ -36,7 +37,7 @@ describe 'nginx::package' do
|
|||
end
|
||||
|
||||
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' }}
|
||||
|
||||
it 'installs 3.0.0 exactly' do
|
||||
|
@ -47,9 +48,10 @@ describe 'nginx::package' do
|
|||
end
|
||||
end
|
||||
|
||||
shared_examples 'debian' do |operatingsystem, lsbdistcodename, lsbdistid|
|
||||
shared_examples 'debian' do |operatingsystem, lsbdistcodename, lsbdistid, operatingsystemmajrelease|
|
||||
let(:facts) {{
|
||||
:operatingsystem => operatingsystem,
|
||||
:operatingsystemmajrelease => operatingsystemmajrelease,
|
||||
:osfamily => 'Debian',
|
||||
:lsbdistcodename => lsbdistcodename,
|
||||
:lsbdistid => lsbdistid
|
||||
|
@ -59,7 +61,7 @@ describe 'nginx::package' do
|
|||
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}",
|
||||
'location' => "http://nginx.org/packages/#{operatingsystem.downcase}",
|
||||
'repos' => 'nginx',
|
||||
'key' => '7BD9BF62',
|
||||
'key_source' => 'http://nginx.org/keys/nginx_signing.key'
|
||||
|
@ -88,36 +90,15 @@ describe 'nginx::package' do
|
|||
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
|
||||
it_behaves_like 'redhat', 'centos'
|
||||
it_behaves_like 'redhat', 'rhel'
|
||||
it_behaves_like 'redhat', 'redhat'
|
||||
it_behaves_like 'redhat', 'scientific'
|
||||
it_behaves_like 'redhat', 'amazon'
|
||||
it_behaves_like 'redhat', 'CentOS'
|
||||
it_behaves_like 'redhat', 'RedHat'
|
||||
end
|
||||
|
||||
context 'debian' do
|
||||
it_behaves_like 'debian', 'debian', 'wheezy', 'debian'
|
||||
it_behaves_like 'debian', 'ubuntu', 'precise', 'ubuntu'
|
||||
it_behaves_like 'debian', 'Debian', 'wheezy', 'Debian', '6'
|
||||
it_behaves_like 'debian', 'Ubuntu', 'precise', 'Ubuntu', '12.04'
|
||||
end
|
||||
|
||||
context 'suse' do
|
||||
it_behaves_like 'suse', 'opensuse'
|
||||
it_behaves_like 'suse', 'suse'
|
||||
end
|
||||
|
||||
context 'amazon with facter < 1.7.2' do
|
||||
let(:facts) {{ :operatingsystem => 'Amazon', :osfamily => 'Linux' }}
|
||||
it { is_expected.to contain_package('nginx') }
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
require 'spec_helper'
|
||||
describe 'nginx::service' do
|
||||
|
||||
let :facts do {
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
} end
|
||||
|
||||
let :params do {
|
||||
:configtest_enable => false,
|
||||
:service_restart => '/etc/init.d/nginx configtest && /etc/init.d/nginx restart',
|
||||
|
|
|
@ -17,13 +17,6 @@ describe 'nginx::resource::geo' do
|
|||
}
|
||||
end
|
||||
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystem => 'CentOS',
|
||||
}
|
||||
end
|
||||
|
||||
let :pre_condition do
|
||||
[
|
||||
'include ::nginx::config',
|
||||
|
|
|
@ -5,12 +5,6 @@ describe 'nginx::resource::location' do
|
|||
let :title do
|
||||
'rspec-test'
|
||||
end
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
}
|
||||
end
|
||||
let :pre_condition do
|
||||
[
|
||||
'include ::nginx::config',
|
||||
|
|
|
@ -6,8 +6,6 @@ describe 'nginx::resource::mailhost' do
|
|||
end
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:ipaddress6 => '::',
|
||||
}
|
||||
end
|
||||
|
|
|
@ -17,13 +17,6 @@ describe 'nginx::resource::map' do
|
|||
}
|
||||
end
|
||||
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystem => 'CentOS',
|
||||
}
|
||||
end
|
||||
|
||||
let :pre_condition do
|
||||
[
|
||||
'include ::nginx::config',
|
||||
|
|
|
@ -17,14 +17,6 @@ describe 'nginx::resource::upstream' do
|
|||
]
|
||||
end
|
||||
|
||||
let :default_facts do
|
||||
{
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystem => 'CentOS',
|
||||
:concat_basedir => '/var/lib/puppet/concat'
|
||||
}
|
||||
end
|
||||
|
||||
let :pre_condition do
|
||||
[
|
||||
'include ::nginx::config',
|
||||
|
@ -32,8 +24,6 @@ describe 'nginx::resource::upstream' do
|
|||
end
|
||||
|
||||
describe 'os-independent items' do
|
||||
let :facts do default_facts end
|
||||
|
||||
describe 'basic assumptions' do
|
||||
let :params do default_params end
|
||||
|
||||
|
@ -67,7 +57,6 @@ describe 'nginx::resource::upstream' do
|
|||
end
|
||||
|
||||
describe "upstream.conf template content" do
|
||||
let :facts do default_facts end
|
||||
[
|
||||
{
|
||||
:title => 'should contain ordered prepended directives',
|
||||
|
|
|
@ -12,8 +12,6 @@ describe 'nginx::resource::vhost' do
|
|||
end
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'debian',
|
||||
:ipaddress6 => '::',
|
||||
}
|
||||
end
|
||||
|
|
|
@ -2,7 +2,6 @@ require 'puppetlabs_spec_helper/module_spec_helper'
|
|||
|
||||
RSpec.configure do |c|
|
||||
c.default_facts = {
|
||||
:kernel => 'Linux',
|
||||
:concat_basedir => '/var/lib/puppet/concat',
|
||||
}
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue