module-nginx/spec/classes/package_spec.rb

117 lines
4.7 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe 'nginx::package' do
shared_examples 'redhat' do |operatingsystem|
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'RedHat', :operatingsystemmajrelease => '6' }}
2013-11-22 04:10:53 +01:00
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/#{operatingsystem == 'CentOS' ? 'centos' : 'rhel'}/6/$basearch/",
2013-11-22 04:10:53 +01:00
'descr' => 'nginx repo',
'enabled' => '1',
'gpgcheck' => '1',
'priority' => '1',
'gpgkey' => 'http://nginx.org/keys/nginx_signing.key'
)}
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]') }
2013-11-22 04:10:53 +01:00
end
context "package_source => nginx-mainline" do
let(:params) {{ :package_source => 'nginx-mainline' }}
it { is_expected.to contain_yumrepo('nginx-release').with(
'baseurl' => "http://nginx.org/packages/mainline/#{operatingsystem == 'CentOS' ? 'centos' : 'rhel'}/6/$basearch/",
)}
end
2013-11-22 04:10:53 +01:00
context "manage_repo => false" do
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'RedHat', :operatingsystemmajrelease => '7' }}
2013-11-22 04:10:53 +01:00
let(:params) {{ :manage_repo => false }}
it { is_expected.to contain_package('nginx') }
it { is_expected.not_to contain_yumrepo('nginx-release') }
2013-11-22 04:10:53 +01:00
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/#{operatingsystem == 'CentOS' ? 'centos' : 'rhel'}/5/$basearch/"
2013-11-22 04:10:53 +01:00
)}
end
describe 'installs the requested package version' do
let(:facts) {{ :operatingsystem => 'redhat', :osfamily => 'redhat', :operatingsystemmajrelease => '7'}}
2013-11-22 04:10:53 +01:00
let(:params) {{ :package_ensure => '3.0.0' }}
it 'installs 3.0.0 exactly' do
is_expected.to contain_package('nginx').with({
2013-11-22 04:10:53 +01:00
'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
}}
2013-11-22 04:10:53 +01:00
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}",
2013-11-22 04:10:53 +01:00
'repos' => 'nginx',
2015-03-24 19:28:46 +01:00
'key' => '573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62',
2013-11-22 04:10:53 +01:00
)}
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]') }
2013-11-22 04:10:53 +01:00
end
context "package_source => nginx-mainline" do
let(:params) {{ :package_source => 'nginx-mainline' }}
it { is_expected.to contain_apt__source('nginx').with(
'location' => "http://nginx.org/packages/mainline/#{operatingsystem.downcase}",
)}
end
2013-11-22 04:10:53 +01:00
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(
2013-11-22 04:10:53 +01:00
'location' => 'https://oss-binaries.phusionpassenger.com/apt/passenger',
'repos' => "main",
'key' => '16378A33A6EF16762922526E561F9B9CAC40B2F7',
2013-11-22 04:10:53 +01:00
)}
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') }
2013-11-22 04:10:53 +01:00
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 'other' do
2013-11-22 04:10:53 +01:00
let(:facts) {{ :operatingsystem => 'xxx', :osfamily => 'linux' }}
it { is_expected.to contain_package('nginx') }
end
end