module-nginx/spec/classes/package_spec.rb
Matthew Haughton 1898182c6d 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.
2014-12-09 19:47:05 -05:00

131 lines
5.6 KiB
Ruby

require 'spec_helper'
describe 'nginx::package' do
shared_examples 'redhat' do |operatingsystem|
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(
'baseurl' => 'http://nginx.org/packages/rhel/6/$basearch/',
'descr' => 'nginx repo',
'enabled' => '1',
'gpgcheck' => '1',
'priority' => '1',
'gpgkey' => 'http://nginx.org/keys/nginx_signing.key'
)}
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(: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 "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/'
)}
it { is_expected.to contain_file('/etc/yum.repos.d/nginx-release.repo') }
end
describe 'installs the requested package version' do
let(:facts) {{ :operatingsystem => 'redhat', :osfamily => 'redhat', :operatingsystemmajrelease => '7'}}
let(:params) {{ :package_ensure => '3.0.0' }}
it 'installs 3.0.0 exactly' do
is_expected.to contain_package('nginx').with({
'ensure' => '3.0.0'
})
end
end
end
shared_examples 'debian' do |operatingsystem, lsbdistcodename, lsbdistid, operatingsystemmajrelease|
let(:facts) {{
:operatingsystem => operatingsystem,
:operatingsystemmajrelease => operatingsystemmajrelease,
:osfamily => 'Debian',
:lsbdistcodename => lsbdistcodename,
:lsbdistid => lsbdistid
}}
context "using defaults" 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.downcase}",
'repos' => 'nginx',
'key' => '7BD9BF62',
'key_source' => 'http://nginx.org/keys/nginx_signing.key'
)}
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 { 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',
'key_source' => 'https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt'
)}
end
context "manage_repo => false" do
let(:params) {{ :manage_repo => false }}
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
context 'redhat' do
it_behaves_like 'redhat', 'CentOS'
it_behaves_like 'redhat', 'RedHat'
end
context 'debian' do
it_behaves_like 'debian', 'Debian', 'wheezy', 'Debian', '6'
it_behaves_like 'debian', 'Ubuntu', 'precise', 'Ubuntu', '12.04'
end
context 'amazon with facter < 1.7.2' do
let(:facts) {{ :operatingsystem => 'Amazon', :osfamily => 'Linux' }}
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',
'gpgcheck' => '1',
'priority' => '1',
'gpgkey' => 'http://nginx.org/keys/nginx_signing.key'
)}
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 { 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
let(:facts) {{ :operatingsystem => 'xxx', :osfamily => 'linux' }}
it { expect { subject }.to raise_error(Puppet::Error, /Module nginx is not supported on xxx/) }
end
end