Revision b4a0d1bf
Added by Pall Valmundsson over 8 years ago
spec/classes/puppet_agent_install_spec.rb | ||
---|---|---|
require 'spec_helper'
|
||
|
||
describe 'puppet::agent::install' do
|
||
on_supported_os.each do |os, os_facts|
|
||
next if only_test_os() and not only_test_os.include?(os)
|
||
next if exclude_test_os() and exclude_test_os.include?(os)
|
||
context "on #{os}" do
|
||
let (:default_facts) do
|
||
os_facts.merge({
|
||
:concat_basedir => '/nonexistant',
|
||
:puppetversion => Puppet.version,
|
||
}) end
|
||
|
||
if Puppet.version < '4.0'
|
||
client_package = 'puppet'
|
||
additional_facts = {}
|
||
else
|
||
client_package = 'puppet-agent'
|
||
additional_facts = {:rubysitedir => '/opt/puppetlabs/puppet/lib/ruby/site_ruby/2.1.0'}
|
||
end
|
||
|
||
if Puppet.version < '4.0'
|
||
additional_facts = {}
|
||
else
|
||
additional_facts = {:rubysitedir => '/opt/puppetlabs/puppet/lib/ruby/site_ruby/2.1.0'}
|
||
end
|
||
let (:facts) do
|
||
default_facts.merge(additional_facts)
|
||
end
|
||
|
||
let :common_centos_facts do on_supported_os['centos-6-x86_64'].merge({
|
||
:concat_basedir => '/nonexistant',
|
||
:puppetversion => Puppet.version,
|
||
}).merge(additional_facts) end
|
||
describe 'with default parameters' do
|
||
let :pre_condition do
|
||
'include ::puppet'
|
||
end
|
||
|
||
describe 'with default parameters' do
|
||
let :pre_condition do
|
||
'include ::puppet'
|
||
end
|
||
it 'should not define provider' do
|
||
should contain_package(client_package).without_provider(nil)
|
||
end
|
||
end
|
||
|
||
if Puppet.version < '4.0'
|
||
client_package = 'puppet'
|
||
else
|
||
client_package = 'puppet-agent'
|
||
end
|
||
describe "when manage_packages => false" do
|
||
let :pre_condition do
|
||
"class { 'puppet': manage_packages => false }"
|
||
end
|
||
|
||
context "on a RedHat family OS" do
|
||
let :facts do
|
||
common_centos_facts
|
||
end
|
||
it 'should not contain Package[puppet]' do
|
||
should_not contain_package('puppet')
|
||
end
|
||
|
||
it 'should not define provider' do
|
||
should contain_package(client_package).without_provider(nil)
|
||
it 'should not contain Package[puppet-agent]' do
|
||
should_not contain_package('puppet-agent')
|
||
end
|
||
end
|
||
end
|
||
|
||
context "on a Windows family OS" do
|
||
let :facts do
|
||
{
|
||
:osfamily => 'windows',
|
||
:concat_basedir => 'C:\Temp',
|
||
:puppetversion => Puppet.version,
|
||
}
|
||
end
|
||
describe "when manage_packages => 'agent'" do
|
||
let :pre_condition do
|
||
"class { 'puppet': manage_packages => 'agent' }"
|
||
end
|
||
|
||
it 'should define provider as chocolatey' do
|
||
should contain_package(client_package).with_provider('chocolatey')
|
||
it 'should contain Package[puppet]' do
|
||
should contain_package(client_package)
|
||
end
|
||
end
|
||
end
|
||
|
||
end
|
||
describe "when manage_packages => 'server'" do
|
||
let :pre_condition do
|
||
"class { 'puppet': manage_packages => 'server' }"
|
||
end
|
||
|
||
describe "when package_provider => 'msi'" do
|
||
it 'should not contain Package[puppet]' do
|
||
should_not contain_package('puppet')
|
||
end
|
||
|
||
if Puppet.version < '4.0'
|
||
client_package = 'puppet'
|
||
else
|
||
client_package = 'puppet-agent'
|
||
end
|
||
it 'should not contain Package[puppet-agent]' do
|
||
should_not contain_package('puppet-agent')
|
||
end
|
||
end
|
||
|
||
let :pre_condition do
|
||
"class { 'puppet': package_provider => 'msi', }"
|
||
end
|
||
end
|
||
|
||
let :facts do
|
||
# Windows is currently not supported by rspec-puppet-facts
|
||
context "on Windows" do
|
||
let :default_facts do
|
||
{
|
||
:osfamily => 'windows',
|
||
:concat_basedir => 'C:\Temp',
|
||
... | ... | |
}
|
||
end
|
||
|
||
it 'should define provider as msi' do
|
||
should contain_package(client_package).with_provider('msi')
|
||
end
|
||
|
||
end
|
||
|
||
describe "when package_provider => 'windows' and source is defined" do
|
||
|
||
if Puppet.version < '4.0'
|
||
client_package = 'puppet'
|
||
additional_facts = {}
|
||
else
|
||
client_package = 'puppet-agent'
|
||
additional_facts = {}
|
||
end
|
||
|
||
let :pre_condition do
|
||
"class { 'puppet': package_provider => 'windows', package_source => 'C:\\Temp\\puppet.exe' }"
|
||
let (:facts) do
|
||
default_facts.merge(additional_facts)
|
||
end
|
||
|
||
let :facts do
|
||
{
|
||
:osfamily => 'windows',
|
||
:concat_basedir => 'C:\Temp',
|
||
:puppetversion => Puppet.version,
|
||
}
|
||
end
|
||
|
||
it 'should define provider as windows' do
|
||
should contain_package(client_package).with_provider('windows')
|
||
end
|
||
|
||
it 'should define source as C:\Temp\puppet.exe' do
|
||
should contain_package(client_package).with_source('C:\Temp\puppet.exe')
|
||
end
|
||
|
||
end
|
||
|
||
describe "when manage_packages => false" do
|
||
let :pre_condition do
|
||
"class { 'puppet': manage_packages => false }"
|
||
end
|
||
|
||
context "on a RedHat family OS" do
|
||
let :facts do
|
||
common_centos_facts
|
||
end
|
||
|
||
it 'should not contain Package[puppet]' do
|
||
should_not contain_package('puppet')
|
||
describe 'with default parameters' do
|
||
let :pre_condition do
|
||
'include ::puppet'
|
||
end
|
||
|
||
it 'should not contain Package[puppet-agent]' do
|
||
should_not contain_package('puppet-agent')
|
||
it 'should define provider as chocolatey' do
|
||
should contain_package(client_package).with_provider('chocolatey')
|
||
end
|
||
end
|
||
end
|
||
|
||
describe "when manage_packages => 'agent'" do
|
||
let :pre_condition do
|
||
"class { 'puppet': manage_packages => 'agent' }"
|
||
end
|
||
|
||
if Puppet.version < '4.0'
|
||
client_package = 'puppet'
|
||
else
|
||
client_package = 'puppet-agent'
|
||
end
|
||
|
||
context "on a RedHat family OS" do
|
||
let :facts do
|
||
common_centos_facts
|
||
describe "when package_provider => 'msi'" do
|
||
let :pre_condition do
|
||
"class { 'puppet': package_provider => 'msi', }"
|
||
end
|
||
|
||
it 'should contain Package[puppet]' do
|
||
should contain_package(client_package)
|
||
it 'should define provider as msi' do
|
||
should contain_package(client_package).with_provider('msi')
|
||
end
|
||
end
|
||
end
|
||
|
||
describe "when manage_packages => 'server'" do
|
||
let :pre_condition do
|
||
"class { 'puppet': manage_packages => 'server' }"
|
||
end
|
||
|
||
context "on a RedHat family OS" do
|
||
let :facts do
|
||
common_centos_facts
|
||
describe "when package_provider => 'windows' and source is defined" do
|
||
let :pre_condition do
|
||
"class { 'puppet': package_provider => 'windows', package_source => 'C:\\Temp\\puppet.exe' }"
|
||
end
|
||
|
||
it 'should not contain Package[puppet]' do
|
||
should_not contain_package('puppet')
|
||
it 'should define provider as windows' do
|
||
should contain_package(client_package).with_provider('windows')
|
||
end
|
||
|
||
it 'should not contain Package[puppet-agent]' do
|
||
should_not contain_package('puppet-agent')
|
||
it 'should define source as C:\Temp\puppet.exe' do
|
||
should contain_package(client_package).with_source('C:\Temp\puppet.exe')
|
||
end
|
||
end
|
||
end
|
||
|
||
end
|
Also available in: Unified diff
refactor rspec tests for speed and coverage
Before this change most tests would only run on centos-6-x86_64 and take
a long time to run since on_supported_os would be evaluated for each
example.
This change reduces the time to run tests as on_supported_os is only
evaluated once per file as well as testing all OSes that on_supported_os
returns. When enabling testing other platforms various failures
emerged, mostly for FreeBSD, that were fixed by adjusting variables
where they were either missing or needed to be adjusted for e.g.
FreeBSD. Redundant examples were removed but since Windows is not
currently supported by on_supported_os all Windows specific tests are
left untouched.
This increases the test examples from 431 to 2276 while lowering the
current total execution time of the 431 examples. But since the
execution time of the whole suite across the whole matrix of platforms
still takes "too long" an option was introduced to reduce the set of
tested platforms to a comma seperated list. The option can be set with
the environment variable LIMIT_OS, e.g.
LIMIT_OS=centos-7-x86_64,ubuntu-14-x86_64.
closes GH-318