diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index a79a444..fea3911 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -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 diff --git a/spec/classes/nginx_spec.rb b/spec/classes/nginx_spec.rb index 9686f26..114fbeb 100644 --- a/spec/classes/nginx_spec.rb +++ b/spec/classes/nginx_spec.rb @@ -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 diff --git a/spec/classes/package_spec.rb b/spec/classes/package_spec.rb index 04bb589..482eb84 100644 --- a/spec/classes/package_spec.rb +++ b/spec/classes/package_spec.rb @@ -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') } diff --git a/spec/classes/service_spec.rb b/spec/classes/service_spec.rb index d6005d5..f737b55 100644 --- a/spec/classes/service_spec.rb +++ b/spec/classes/service_spec.rb @@ -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', diff --git a/spec/defines/resource_geo_spec.rb b/spec/defines/resource_geo_spec.rb index 94958f6..537be25 100644 --- a/spec/defines/resource_geo_spec.rb +++ b/spec/defines/resource_geo_spec.rb @@ -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', diff --git a/spec/defines/resource_location_spec.rb b/spec/defines/resource_location_spec.rb index 1333033..d159a90 100644 --- a/spec/defines/resource_location_spec.rb +++ b/spec/defines/resource_location_spec.rb @@ -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', diff --git a/spec/defines/resource_mailhost_spec.rb b/spec/defines/resource_mailhost_spec.rb index 36237cf..5e6a6f5 100644 --- a/spec/defines/resource_mailhost_spec.rb +++ b/spec/defines/resource_mailhost_spec.rb @@ -6,8 +6,6 @@ describe 'nginx::resource::mailhost' do end let :facts do { - :osfamily => 'Debian', - :operatingsystem => 'Debian', :ipaddress6 => '::', } end diff --git a/spec/defines/resource_map_spec.rb b/spec/defines/resource_map_spec.rb index e6d262e..b10665f 100644 --- a/spec/defines/resource_map_spec.rb +++ b/spec/defines/resource_map_spec.rb @@ -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', diff --git a/spec/defines/resource_upstream_spec.rb b/spec/defines/resource_upstream_spec.rb index 148d8da..ce7d0d6 100644 --- a/spec/defines/resource_upstream_spec.rb +++ b/spec/defines/resource_upstream_spec.rb @@ -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', diff --git a/spec/defines/resource_vhost_spec.rb b/spec/defines/resource_vhost_spec.rb index 24dafa8..f8c6616 100644 --- a/spec/defines/resource_vhost_spec.rb +++ b/spec/defines/resource_vhost_spec.rb @@ -12,8 +12,6 @@ describe 'nginx::resource::vhost' do end let :facts do { - :osfamily => 'Debian', - :operatingsystem => 'debian', :ipaddress6 => '::', } end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a987b6e..415c941 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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