Cleaned up unit tests.
This commit is contained in:
parent
ce846d0118
commit
5d7982dba0
14 changed files with 1005 additions and 1208 deletions
|
@ -16,7 +16,6 @@ define apt::pin(
|
|||
$originator = '', # o=
|
||||
$label = '' # l=
|
||||
) {
|
||||
|
||||
include apt::params
|
||||
|
||||
$preferences_d = $apt::params::preferences_d
|
||||
|
@ -35,7 +34,7 @@ define apt::pin(
|
|||
$pin_release = join($pin_release_array, '')
|
||||
|
||||
# Read the manpage 'apt_preferences(5)', especially the chapter
|
||||
# 'Thea Effect of APT Preferences' to understand the following logic
|
||||
# 'The Effect of APT Preferences' to understand the following logic
|
||||
# and the difference between specific and general form
|
||||
if is_array($packages) {
|
||||
$packages_string = join($packages, ' ')
|
||||
|
@ -44,24 +43,17 @@ define apt::pin(
|
|||
}
|
||||
|
||||
if $packages_string != '*' { # specific form
|
||||
|
||||
if ( $pin_release != '' and ( $origin != '' or $version != '' )) or
|
||||
( $origin != '' and ( $pin_release != '' or $version != '' )) or
|
||||
( $version != '' and ( $pin_release != '' or $origin != '' )) {
|
||||
fail('parameters release, origin, and version are mutually exclusive')
|
||||
}
|
||||
|
||||
} else { # general form
|
||||
|
||||
if $version != '' {
|
||||
fail('parameter version cannot be used in general form')
|
||||
}
|
||||
|
||||
if ( $pin_release != '' and $origin != '' ) or
|
||||
( $origin != '' and $pin_release != '' ) {
|
||||
fail('parmeters release and origin are mutually exclusive')
|
||||
if ( $pin_release != '' and $origin != '' ) {
|
||||
fail('parameters release and origin are mutually exclusive')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -69,9 +69,6 @@ define apt::ppa(
|
|||
|
||||
file { "${sources_list_d}/${sources_list_d_filename}":
|
||||
ensure => 'absent',
|
||||
mode => '0644',
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
notify => Exec['apt_update'],
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,18 +52,21 @@ class apt::unattended_upgrades (
|
|||
ensure => present,
|
||||
}
|
||||
|
||||
File {
|
||||
file { '/etc/apt/apt.conf.d/50unattended-upgrades':
|
||||
ensure => file,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
content => template('apt/50unattended-upgrades.erb'),
|
||||
require => Package['unattended-upgrades'],
|
||||
}
|
||||
|
||||
file {
|
||||
'/etc/apt/apt.conf.d/50unattended-upgrades':
|
||||
content => template('apt/50unattended-upgrades.erb');
|
||||
'/etc/apt/apt.conf.d/10periodic':
|
||||
content => template('apt/10periodic.erb');
|
||||
file { '/etc/apt/apt.conf.d/10periodic':
|
||||
ensure => file,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
content => template('apt/10periodic.erb'),
|
||||
require => Package['unattended-upgrades'],
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,170 +1,257 @@
|
|||
require 'spec_helper'
|
||||
describe 'apt', :type => :class do
|
||||
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
|
||||
let :default_params do
|
||||
{
|
||||
:disable_keys => :undef,
|
||||
:always_apt_update => false,
|
||||
:purge_sources_list => false,
|
||||
:purge_sources_list_d => false,
|
||||
}
|
||||
end
|
||||
|
||||
[{},
|
||||
{
|
||||
:disable_keys => true,
|
||||
:always_apt_update => true,
|
||||
:proxy_host => true,
|
||||
:proxy_port => '3128',
|
||||
:purge_sources_list => true,
|
||||
:purge_sources_list_d => true,
|
||||
},
|
||||
{
|
||||
:purge_preferences => true,
|
||||
:purge_preferences_d => true,
|
||||
},
|
||||
{
|
||||
:disable_keys => false
|
||||
}
|
||||
].each do |param_set|
|
||||
describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
|
||||
let :param_hash do
|
||||
default_params.merge(param_set)
|
||||
end
|
||||
context 'defaults' do
|
||||
it { should contain_file('sources.list').that_notifies('Exec[apt_update]').only_with({
|
||||
'ensure' => 'present',
|
||||
'path' => '/etc/apt/sources.list',
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'mode' => '0644',
|
||||
'notify' => 'Exec[apt_update]',
|
||||
})}
|
||||
|
||||
let :params do
|
||||
param_set
|
||||
end
|
||||
|
||||
let :refresh_only_apt_update do
|
||||
if param_hash[:always_apt_update]
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
it { should contain_class("apt::params") }
|
||||
|
||||
it {
|
||||
if param_hash[:purge_sources_list]
|
||||
should contain_file("sources.list").with({
|
||||
'path' => "/etc/apt/sources.list",
|
||||
'ensure' => "present",
|
||||
'owner' => "root",
|
||||
'group' => "root",
|
||||
'mode' => "0644",
|
||||
"content" => "# Repos managed by puppet.\n"
|
||||
})
|
||||
else
|
||||
should contain_file("sources.list").with({
|
||||
'path' => "/etc/apt/sources.list",
|
||||
'ensure' => "present",
|
||||
'owner' => "root",
|
||||
'group' => "root",
|
||||
'mode' => "0644",
|
||||
'content' => nil
|
||||
})
|
||||
end
|
||||
}
|
||||
it {
|
||||
if param_hash[:purge_sources_list_d]
|
||||
should create_file("sources.list.d").with({
|
||||
'path' => "/etc/apt/sources.list.d",
|
||||
'ensure' => "directory",
|
||||
'owner' => "root",
|
||||
'group' => "root",
|
||||
'purge' => true,
|
||||
'recurse' => true,
|
||||
'notify' => 'Exec[apt_update]'
|
||||
})
|
||||
else
|
||||
should create_file("sources.list.d").with({
|
||||
'path' => "/etc/apt/sources.list.d",
|
||||
'ensure' => "directory",
|
||||
'owner' => "root",
|
||||
'group' => "root",
|
||||
it { should contain_file('sources.list.d').that_notifies('Exec[apt_update]').only_with({
|
||||
'ensure' => 'directory',
|
||||
'path' => '/etc/apt/sources.list.d',
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'purge' => false,
|
||||
'recurse' => false,
|
||||
'notify' => 'Exec[apt_update]'
|
||||
})
|
||||
end
|
||||
}
|
||||
it {
|
||||
if param_hash[:purge_preferences]
|
||||
should create_file('apt-preferences').with({
|
||||
:ensure => 'absent',
|
||||
:path => '/etc/apt/preferences',
|
||||
})
|
||||
else
|
||||
should_not contain_file('apt-preferences')
|
||||
end
|
||||
}
|
||||
'notify' => 'Exec[apt_update]',
|
||||
})}
|
||||
|
||||
it {
|
||||
if param_hash[:purge_preferences_d]
|
||||
should create_file("preferences.d").with({
|
||||
'path' => "/etc/apt/preferences.d",
|
||||
'ensure' => "directory",
|
||||
'owner' => "root",
|
||||
'group' => "root",
|
||||
'purge' => true,
|
||||
'recurse' => true,
|
||||
})
|
||||
else
|
||||
should create_file("preferences.d").with({
|
||||
'path' => "/etc/apt/preferences.d",
|
||||
'ensure' => "directory",
|
||||
'owner' => "root",
|
||||
'group' => "root",
|
||||
it { should contain_file('preferences.d').only_with({
|
||||
'ensure' => 'directory',
|
||||
'path' => '/etc/apt/preferences.d',
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'purge' => false,
|
||||
'recurse' => false,
|
||||
})
|
||||
end
|
||||
}
|
||||
})}
|
||||
|
||||
it {
|
||||
should contain_exec("apt_update").with({
|
||||
'command' => "/usr/bin/apt-get update",
|
||||
'refreshonly' => refresh_only_apt_update
|
||||
})
|
||||
}
|
||||
|
||||
it {
|
||||
if param_hash[:disable_keys] == true
|
||||
should create_file("99unauth").with({
|
||||
'content' => "APT::Get::AllowUnauthenticated 1;\n",
|
||||
'ensure' => "present",
|
||||
'path' => "/etc/apt/apt.conf.d/99unauth"
|
||||
})
|
||||
elsif param_hash[:disable_keys] == false
|
||||
should create_file("99unauth").with({
|
||||
'ensure' => "absent",
|
||||
'path' => "/etc/apt/apt.conf.d/99unauth"
|
||||
})
|
||||
elsif param_hash[:disable_keys] != :undef
|
||||
should_not create_file("99unauth").with({
|
||||
'path' => "/etc/apt/apt.conf.d/99unauth"
|
||||
})
|
||||
end
|
||||
}
|
||||
describe 'when setting a proxy' do
|
||||
it {
|
||||
if param_hash[:proxy_host]
|
||||
should contain_file('01proxy').with(
|
||||
'path' => '/etc/apt/apt.conf.d/01proxy',
|
||||
'content' => "Acquire::http::Proxy \"http://#{param_hash[:proxy_host]}:#{param_hash[:proxy_port]}\";\n",
|
||||
'notify' => "Exec[apt_update]"
|
||||
)
|
||||
else
|
||||
should contain_file('01proxy').with(
|
||||
it { should contain_file('01proxy').that_notifies('Exec[apt_update]').only_with({
|
||||
'ensure' => 'absent',
|
||||
'path' => '/etc/apt/apt.conf.d/01proxy',
|
||||
'notify' => 'Exec[apt_update]',
|
||||
'ensure' => 'absent'
|
||||
)
|
||||
})}
|
||||
|
||||
it { should contain_file('old-proxy-file').that_notifies('Exec[apt_update]').only_with({
|
||||
'ensure' => 'absent',
|
||||
'path' => '/etc/apt/apt.conf.d/proxy',
|
||||
'notify' => 'Exec[apt_update]',
|
||||
})}
|
||||
|
||||
it { should contain_exec('apt_update').with({
|
||||
'refreshonly' => 'true',
|
||||
})}
|
||||
end
|
||||
|
||||
context 'lots of non-defaults' do
|
||||
let :params do
|
||||
{
|
||||
:always_apt_update => true,
|
||||
:disable_keys => true,
|
||||
:proxy_host => 'foo',
|
||||
:proxy_port => '9876',
|
||||
:purge_sources_list => true,
|
||||
:purge_sources_list_d => true,
|
||||
:purge_preferences => true,
|
||||
:purge_preferences_d => true,
|
||||
:update_timeout => '1',
|
||||
:update_tries => '3',
|
||||
:fancy_progress => true,
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_file('sources.list').with({
|
||||
'content' => "# Repos managed by puppet.\n"
|
||||
})}
|
||||
|
||||
it { should contain_file('sources.list.d').with({
|
||||
'purge' => 'true',
|
||||
'recurse' => 'true',
|
||||
})}
|
||||
|
||||
it { should contain_file('apt-preferences').only_with({
|
||||
'ensure' => 'absent',
|
||||
'path' => '/etc/apt/preferences',
|
||||
})}
|
||||
|
||||
it { should contain_file('preferences.d').with({
|
||||
'purge' => 'true',
|
||||
'recurse' => 'true',
|
||||
})}
|
||||
|
||||
it { should contain_file('99progressbar').only_with({
|
||||
'ensure' => 'present',
|
||||
'content' => 'Dpkg::Progress-Fancy "1";',
|
||||
'path' => '/etc/apt/apt.conf.d/99progressbar',
|
||||
})}
|
||||
|
||||
it { should contain_file('99unauth').only_with({
|
||||
'ensure' => 'present',
|
||||
'content' => "APT::Get::AllowUnauthenticated 1;\n",
|
||||
'path' => '/etc/apt/apt.conf.d/99unauth',
|
||||
})}
|
||||
|
||||
it { should contain_file('01proxy').that_notifies('Exec[apt_update]').only_with({
|
||||
'ensure' => 'present',
|
||||
'path' => '/etc/apt/apt.conf.d/01proxy',
|
||||
'content' => "Acquire::http::Proxy \"http://foo:9876\";\n",
|
||||
'notify' => 'Exec[apt_update]',
|
||||
'mode' => '0644',
|
||||
'owner' => 'root',
|
||||
'group' => 'root'
|
||||
})}
|
||||
|
||||
it { should contain_exec('apt_update').with({
|
||||
'refreshonly' => 'false',
|
||||
'timeout' => '1',
|
||||
'tries' => '3',
|
||||
})}
|
||||
|
||||
end
|
||||
|
||||
context 'more non-default' do
|
||||
let :params do
|
||||
{
|
||||
:fancy_progress => false,
|
||||
:disable_keys => false,
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_file('99progressbar').only_with({
|
||||
'ensure' => 'absent',
|
||||
'path' => '/etc/apt/apt.conf.d/99progressbar',
|
||||
})}
|
||||
|
||||
it { should contain_file('99unauth').only_with({
|
||||
'ensure' => 'absent',
|
||||
'path' => '/etc/apt/apt.conf.d/99unauth',
|
||||
})}
|
||||
|
||||
end
|
||||
|
||||
context 'with sources defined on valid osfamily' do
|
||||
let :facts do
|
||||
{ :osfamily => 'Debian',
|
||||
:lsbdistcodename => 'precise',
|
||||
:lsbdistid => 'Debian',
|
||||
}
|
||||
end
|
||||
let(:params) { { :sources => {
|
||||
'debian_unstable' => {
|
||||
'location' => 'http://debian.mirror.iweb.ca/debian/',
|
||||
'release' => 'unstable',
|
||||
'repos' => 'main contrib non-free',
|
||||
'required_packages' => 'debian-keyring debian-archive-keyring',
|
||||
'key' => '55BE302B',
|
||||
'key_server' => 'subkeys.pgp.net',
|
||||
'pin' => '-10',
|
||||
'include_src' => true
|
||||
},
|
||||
'puppetlabs' => {
|
||||
'location' => 'http://apt.puppetlabs.com',
|
||||
'repos' => 'main',
|
||||
'key' => '4BD6EC30',
|
||||
'key_server' => 'pgp.mit.edu',
|
||||
}
|
||||
} } }
|
||||
|
||||
it {
|
||||
should contain_file('debian_unstable.list').with({
|
||||
'ensure' => 'present',
|
||||
'path' => '/etc/apt/sources.list.d/debian_unstable.list',
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'mode' => '0644',
|
||||
'notify' => 'Exec[apt_update]',
|
||||
})
|
||||
}
|
||||
|
||||
it { should contain_file('debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
|
||||
it { should contain_file('debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
|
||||
|
||||
it {
|
||||
should contain_file('puppetlabs.list').with({
|
||||
'ensure' => 'present',
|
||||
'path' => '/etc/apt/sources.list.d/puppetlabs.list',
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'mode' => '0644',
|
||||
'notify' => 'Exec[apt_update]',
|
||||
})
|
||||
}
|
||||
|
||||
it { should contain_file('puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
|
||||
it { should contain_file('puppetlabs.list').with_content(/^deb-src http:\/\/apt.puppetlabs.com precise main$/) }
|
||||
end
|
||||
|
||||
describe 'failing tests' do
|
||||
context 'bad purge_sources_list' do
|
||||
let :params do
|
||||
{
|
||||
'purge_sources_list' => 'foo'
|
||||
}
|
||||
end
|
||||
it do
|
||||
expect {
|
||||
should compile
|
||||
}.to raise_error(Puppet::Error)
|
||||
end
|
||||
end
|
||||
|
||||
context 'bad purge_sources_list_d' do
|
||||
let :params do
|
||||
{
|
||||
'purge_sources_list_d' => 'foo'
|
||||
}
|
||||
end
|
||||
it do
|
||||
expect {
|
||||
should compile
|
||||
}.to raise_error(Puppet::Error)
|
||||
end
|
||||
end
|
||||
|
||||
context 'bad purge_preferences' do
|
||||
let :params do
|
||||
{
|
||||
'purge_preferences' => 'foo'
|
||||
}
|
||||
end
|
||||
it do
|
||||
expect {
|
||||
should compile
|
||||
}.to raise_error(Puppet::Error)
|
||||
end
|
||||
end
|
||||
|
||||
context 'bad purge_preferences_d' do
|
||||
let :params do
|
||||
{
|
||||
'purge_preferences_d' => 'foo'
|
||||
}
|
||||
end
|
||||
it do
|
||||
expect {
|
||||
should compile
|
||||
}.to raise_error(Puppet::Error)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with unsupported osfamily' do
|
||||
let :facts do
|
||||
{ :osfamily => 'Darwin', }
|
||||
end
|
||||
|
||||
it do
|
||||
expect {
|
||||
should compile
|
||||
}.to raise_error(Puppet::Error, /This module only works on Debian or derivatives like Ubuntu/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
require 'spec_helper'
|
||||
describe 'apt' do
|
||||
context 'with sources defined on valid osfamily' do
|
||||
let :facts do
|
||||
{ :osfamily => 'Debian',
|
||||
:lsbdistcodename => 'precise',
|
||||
:lsbdistid => 'Debian',
|
||||
}
|
||||
end
|
||||
let(:params) { { :sources => {
|
||||
'debian_unstable' => {
|
||||
'location' => 'http://debian.mirror.iweb.ca/debian/',
|
||||
'release' => 'unstable',
|
||||
'repos' => 'main contrib non-free',
|
||||
'required_packages' => 'debian-keyring debian-archive-keyring',
|
||||
'key' => '55BE302B',
|
||||
'key_server' => 'subkeys.pgp.net',
|
||||
'pin' => '-10',
|
||||
'include_src' => true
|
||||
},
|
||||
'puppetlabs' => {
|
||||
'location' => 'http://apt.puppetlabs.com',
|
||||
'repos' => 'main',
|
||||
'key' => '4BD6EC30',
|
||||
'key_server' => 'pgp.mit.edu',
|
||||
}
|
||||
} } }
|
||||
|
||||
it {
|
||||
should contain_file('debian_unstable.list').with({
|
||||
'ensure' => 'present',
|
||||
'path' => '/etc/apt/sources.list.d/debian_unstable.list',
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'mode' => '0644',
|
||||
'notify' => 'Exec[apt_update]',
|
||||
})
|
||||
}
|
||||
|
||||
it { should contain_file('debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
|
||||
it { should contain_file('debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
|
||||
|
||||
it {
|
||||
should contain_file('puppetlabs.list').with({
|
||||
'ensure' => 'present',
|
||||
'path' => '/etc/apt/sources.list.d/puppetlabs.list',
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'mode' => '0644',
|
||||
'notify' => 'Exec[apt_update]',
|
||||
})
|
||||
}
|
||||
|
||||
it { should contain_file('puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
|
||||
it { should contain_file('puppetlabs.list').with_content(/^deb-src http:\/\/apt.puppetlabs.com precise main$/) }
|
||||
end
|
||||
|
||||
context 'with unsupported osfamily' do
|
||||
let :facts do
|
||||
{ :osfamily => 'Darwin', }
|
||||
end
|
||||
|
||||
it do
|
||||
expect {
|
||||
should compile
|
||||
}.to raise_error(Puppet::Error, /This module only works on Debian or derivatives like Ubuntu/)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -24,270 +24,165 @@ describe 'apt::unattended_upgrades', :type => :class do
|
|||
})
|
||||
}
|
||||
|
||||
describe "origins" do
|
||||
describe 'on Debian' do
|
||||
default_facts = { :lsbdistid => 'Debian' }
|
||||
describe 'failing' do
|
||||
let :facts do
|
||||
{
|
||||
'lsbdistid' => 'debian',
|
||||
'lsbdistcodename' => 'squeeze',
|
||||
}
|
||||
end
|
||||
context 'bad auto_fix' do
|
||||
let :params do
|
||||
{
|
||||
'auto_fix' => 'foo',
|
||||
}
|
||||
end
|
||||
it { expect { should raise_error(Puppet::Error) } }
|
||||
end
|
||||
|
||||
context 'bad minimal_steps' do
|
||||
let :params do
|
||||
{
|
||||
'minimal_steps' => 'foo',
|
||||
}
|
||||
end
|
||||
it { expect { should raise_error(Puppet::Error) } }
|
||||
end
|
||||
|
||||
context 'bad install_on_shutdown' do
|
||||
let :params do
|
||||
{
|
||||
'install_on_shutdown' => 'foo',
|
||||
}
|
||||
end
|
||||
it { expect { should raise_error(Puppet::Error) } }
|
||||
end
|
||||
|
||||
context 'bad mail_only_on_error' do
|
||||
let :params do
|
||||
{
|
||||
'mail_only_on_error' => 'foo',
|
||||
}
|
||||
end
|
||||
it { expect { should raise_error(Puppet::Error) } }
|
||||
end
|
||||
|
||||
context 'bad remove_unused' do
|
||||
let :params do
|
||||
{
|
||||
'remove_unused' => 'foo',
|
||||
}
|
||||
end
|
||||
it { expect { should raise_error(Puppet::Error) } }
|
||||
end
|
||||
|
||||
context 'bad auto_reboot' do
|
||||
let :params do
|
||||
{
|
||||
'auto_reboot' => 'foo',
|
||||
}
|
||||
end
|
||||
it { expect { should raise_error(Puppet::Error) } }
|
||||
end
|
||||
|
||||
context 'bad origins' do
|
||||
let :params do
|
||||
{
|
||||
'origins' => 'foo'
|
||||
}
|
||||
end
|
||||
it { expect { should raise_error(Puppet::Error) } }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'defaults' do
|
||||
let :facts do default_facts end
|
||||
it {
|
||||
should contain_file(file_unattended).with_content(
|
||||
/^Unattended-Upgrade::Origins-Pattern/
|
||||
).with_content(
|
||||
/"origin=Debian,archive=stable,label=Debian-Security";/
|
||||
)
|
||||
let :facts do
|
||||
{
|
||||
'lsbdistid' => 'debian',
|
||||
'lsbdistcodename' => 'squeeze',
|
||||
}
|
||||
end
|
||||
context 'defaults with custom origin' do
|
||||
let :facts do default_facts end
|
||||
let :params do { :origins => ['bananana']} end
|
||||
it {
|
||||
should contain_file(file_unattended).with_content(
|
||||
/^Unattended-Upgrade::Origins-Pattern/
|
||||
).with_content(
|
||||
/"bananana";/
|
||||
)
|
||||
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Allowed-Origins \{\n\t"\${distro_id} oldstable";\n\t"\${distro_id} \${distro_codename}-security";\n\t"\${distro_id} \${distro_codename}-lts";\n\};} }
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::AutoFixInterruptedDpkg "true";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::MinimalSteps "false";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::InstallOnShutdown "false";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Remove-Unused-Dependencies "true";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Automatic-Reboot "false";}}
|
||||
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Enable "1";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpArchiveInterval "0";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpLevel "3";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxAge "0";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MinAge "0";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxSize "0";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Update-Package-Lists "1";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages "1";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages-Debdelta "0";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Unattended-Upgrade "1";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::AutocleanInterval "7";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Verbose "0";}}
|
||||
end
|
||||
|
||||
context 'anything but defaults' do
|
||||
let :facts do
|
||||
{
|
||||
'lsbdistid' => 'debian',
|
||||
'lsbdistcodename' => 'wheezy',
|
||||
}
|
||||
end
|
||||
context 'defaults with invalid origin' do
|
||||
let :facts do default_facts end
|
||||
let :params do { :origins => 'bananana'} end
|
||||
it {
|
||||
expect {subject}.to raise_error(/is not an Array/)
|
||||
|
||||
let :params do
|
||||
{
|
||||
'enable' => '0',
|
||||
'backup_interval' => '3',
|
||||
'backup_level' => '1',
|
||||
'max_age' => '7',
|
||||
'min_age' => '1',
|
||||
'max_size' => '100',
|
||||
'update' => '0',
|
||||
'download' => '0',
|
||||
'download_delta' => '1',
|
||||
'upgrade' => '0',
|
||||
'autoclean' => '0',
|
||||
'verbose' => '1',
|
||||
'origins' => ['bananas'],
|
||||
'blacklist' => ['foo', 'bar'],
|
||||
'auto_fix' => false,
|
||||
'minimal_steps' => true,
|
||||
'install_on_shutdown' => true,
|
||||
'mail_to' => 'root@localhost',
|
||||
'mail_only_on_error' => true,
|
||||
'remove_unused' => false,
|
||||
'auto_reboot' => true,
|
||||
'dl_limit' => '70',
|
||||
}
|
||||
end
|
||||
context 'squeeze' do
|
||||
let :facts do default_facts.merge({:lsbdistcodename => 'squeeze'}) end
|
||||
it {
|
||||
should contain_file(file_unattended).with_content(
|
||||
/^Unattended-Upgrade::Allowed-Origins/
|
||||
).with_content(
|
||||
/"\${distro_id} \${distro_codename}-lts";/
|
||||
).with_content(
|
||||
/"\${distro_id} \${distro_codename}-security";/
|
||||
).with_content(
|
||||
/"\${distro_id} oldstable";/
|
||||
)
|
||||
}
|
||||
end
|
||||
context 'wheezy' do
|
||||
let :facts do default_facts.merge({:lsbdistcodename => 'wheezy'}) end
|
||||
it {
|
||||
should contain_file(file_unattended).with_content(
|
||||
/^Unattended-Upgrade::Origins-Pattern/
|
||||
).with_content(
|
||||
/"origin=Debian,archive=stable,label=Debian-Security";/
|
||||
)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe 'on Ubuntu' do
|
||||
default_facts = { :lsbdistid => 'Ubuntu' }
|
||||
context 'default' do
|
||||
let :facts do default_facts end
|
||||
it {
|
||||
should contain_file(file_unattended).with_content(
|
||||
/^Unattended-Upgrade::Allowed-Origins/
|
||||
).with_content(
|
||||
/"\${distro_id}\:\${distro_codename}-security";/
|
||||
)
|
||||
}
|
||||
end
|
||||
context 'lucid' do
|
||||
let :facts do default_facts.merge({:lsbdistcodename => 'lucid'}) end
|
||||
it {
|
||||
should contain_file(file_unattended).with_content(
|
||||
/^Unattended-Upgrade::Allowed-Origins/
|
||||
).with_content(
|
||||
/"\${distro_id} \${distro_codename}-security";/
|
||||
)
|
||||
}
|
||||
end
|
||||
context 'precise' do
|
||||
let :facts do default_facts.merge({:lsbdistcodename => 'precise'}) end
|
||||
it {
|
||||
should contain_file(file_unattended).with_content(
|
||||
/^Unattended-Upgrade::Allowed-Origins/
|
||||
).with_content(
|
||||
/"\${distro_id}\:\${distro_codename}-security";/
|
||||
)
|
||||
}
|
||||
end
|
||||
context 'trusty' do
|
||||
let :facts do default_facts.merge({:lsbdistcodename => 'trusty'}) end
|
||||
it {
|
||||
should contain_file(file_unattended).with_content(
|
||||
/^Unattended-Upgrade::Allowed-Origins/
|
||||
).with_content(
|
||||
/"\${distro_id}\:\${distro_codename}-security";/
|
||||
)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Origins-Pattern \{\n\t"bananas";\n\};} }
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Package-Blacklist \{\n\t"foo";\n\t"bar";\n\};} }
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::AutoFixInterruptedDpkg "false";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::MinimalSteps "true";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::InstallOnShutdown "true";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Mail "root@localhost";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::MailOnlyOnError "true";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Remove-Unused-Dependencies "false";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Automatic-Reboot "true";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Acquire::http::Dl-Limit "70";}}
|
||||
|
||||
describe "blacklist" do
|
||||
describe "with param defaults" do
|
||||
let(:params) {{ }}
|
||||
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\};$/) }
|
||||
end
|
||||
|
||||
describe "with blacklist => []" do
|
||||
let :params do
|
||||
{ :blacklist => ['libc6', 'libc6-dev'] }
|
||||
end
|
||||
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\t"libc6";\n\t"libc6-dev";\n\};$/) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "with update => 2" do
|
||||
let :params do
|
||||
{ :update => "2" }
|
||||
end
|
||||
it { should contain_file(file_periodic).with_content(/^APT::Periodic::Update-Package-Lists "2";$/) }
|
||||
end
|
||||
|
||||
describe "with download => 2" do
|
||||
let :params do
|
||||
{ :download => "2" }
|
||||
end
|
||||
it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages "2";$/) }
|
||||
end
|
||||
|
||||
describe "with upgrade => 2" do
|
||||
let :params do
|
||||
{ :upgrade => "2" }
|
||||
end
|
||||
it { should contain_file(file_periodic).with_content(/^APT::Periodic::Unattended-Upgrade "2";$/) }
|
||||
end
|
||||
|
||||
describe "with autoclean => 2" do
|
||||
let :params do
|
||||
{ :autoclean => "2" }
|
||||
end
|
||||
it { should contain_file(file_periodic).with_content(/^APT::Periodic::AutocleanInterval "2";$/) }
|
||||
end
|
||||
|
||||
describe "with auto_fix => false" do
|
||||
let :params do
|
||||
{ :auto_fix => false }
|
||||
end
|
||||
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::AutoFixInterruptedDpkg "false";$/) }
|
||||
end
|
||||
|
||||
describe "with minimal_steps => true" do
|
||||
let :params do
|
||||
{ :minimal_steps => true }
|
||||
end
|
||||
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MinimalSteps "true";$/) }
|
||||
end
|
||||
|
||||
describe "with install_on_shutdown => true" do
|
||||
let :params do
|
||||
{ :install_on_shutdown => true }
|
||||
end
|
||||
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::InstallOnShutdown "true";$/) }
|
||||
end
|
||||
|
||||
describe "mail_to" do
|
||||
describe "param defaults" do
|
||||
let(:params) {{ }}
|
||||
it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail /) }
|
||||
it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError /) }
|
||||
end
|
||||
|
||||
describe "with mail_to => user@website, mail_only_on_error => true" do
|
||||
let :params do
|
||||
{ :mail_to => "user@website",
|
||||
:mail_only_on_error => true }
|
||||
end
|
||||
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail "user@website";$/) }
|
||||
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError "true";$/) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "with remove_unused => false" do
|
||||
let :params do
|
||||
{ :remove_unused => false }
|
||||
end
|
||||
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Remove-Unused-Dependencies "false";$/) }
|
||||
end
|
||||
|
||||
describe "with auto_reboot => true" do
|
||||
let :params do
|
||||
{ :auto_reboot => true }
|
||||
end
|
||||
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Automatic-Reboot "true";$/) }
|
||||
end
|
||||
|
||||
describe "dl_limit" do
|
||||
describe "param defaults" do
|
||||
let(:params) {{ }}
|
||||
it { should_not contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit /) }
|
||||
end
|
||||
|
||||
describe "with dl_limit => 70" do
|
||||
let :params do
|
||||
{ :dl_limit => "70" }
|
||||
end
|
||||
it { should contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit "70";$/) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "with enable => 0" do
|
||||
let :params do
|
||||
{ :enable => "0" }
|
||||
end
|
||||
it { should contain_file(file_periodic).with_content(/^APT::Periodic::Enable "0";$/) }
|
||||
end
|
||||
|
||||
describe "with backup_interval => 1" do
|
||||
let :params do
|
||||
{ :backup_interval => "1" }
|
||||
end
|
||||
it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpArchiveInterval "1";$/) }
|
||||
end
|
||||
|
||||
describe "with backup_level => 0" do
|
||||
let :params do
|
||||
{ :backup_level => "0" }
|
||||
end
|
||||
it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpLevel "0";$/) }
|
||||
end
|
||||
|
||||
describe "with max_age => 1" do
|
||||
let :params do
|
||||
{ :max_age => "1" }
|
||||
end
|
||||
it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxAge "1";$/) }
|
||||
end
|
||||
|
||||
describe "with min_age => 1" do
|
||||
let :params do
|
||||
{ :min_age => "1" }
|
||||
end
|
||||
it { should contain_file(file_periodic).with_content(/^APT::Periodic::MinAge "1";$/) }
|
||||
end
|
||||
|
||||
describe "with max_size => 1" do
|
||||
let :params do
|
||||
{ :max_size => "1" }
|
||||
end
|
||||
it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxSize "1";$/) }
|
||||
end
|
||||
|
||||
describe "with download_delta => 2" do
|
||||
let :params do
|
||||
{ :download_delta => "2" }
|
||||
end
|
||||
it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";$/) }
|
||||
end
|
||||
|
||||
describe "with verbose => 2" do
|
||||
let :params do
|
||||
{ :verbose => "2" }
|
||||
end
|
||||
it { should contain_file(file_periodic).with_content(/^APT::Periodic::Verbose "2";$/) }
|
||||
end
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Enable "0";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpArchiveInterval "3";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpLevel "1";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxAge "7";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MinAge "1";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxSize "100";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Update-Package-Lists "0";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages "0";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages-Debdelta "1";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Unattended-Upgrade "0";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::AutocleanInterval "0";}}
|
||||
it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Verbose "1";}}
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,10 +4,10 @@ describe 'apt::builddep', :type => :define do
|
|||
let(:facts) { { :lsbdistid => 'Debian' } }
|
||||
let(:title) { 'my_package' }
|
||||
|
||||
describe "should require apt-get update" do
|
||||
it { should contain_exec("apt_update").with({
|
||||
'command' => "/usr/bin/apt-get update",
|
||||
'refreshonly' => true
|
||||
describe "defaults" do
|
||||
it { should contain_exec("apt-builddep-my_package").that_notifies('Exec[apt_update]').with({
|
||||
'command' => "/usr/bin/apt-get -y --force-yes build-dep my_package",
|
||||
'logoutput' => 'on_failure'
|
||||
})
|
||||
}
|
||||
it { should contain_anchor("apt::builddep::my_package").with({
|
||||
|
|
|
@ -17,12 +17,6 @@ describe 'apt::conf', :type => :define do
|
|||
"/etc/apt/apt.conf.d/00norecommends"
|
||||
end
|
||||
|
||||
it { should contain_apt__conf('norecommends').with({
|
||||
'priority' => '00',
|
||||
'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
|
||||
})
|
||||
}
|
||||
|
||||
it { should contain_file(filename).with({
|
||||
'ensure' => 'present',
|
||||
'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
|
||||
|
|
|
@ -17,11 +17,9 @@ describe 'apt::force', :type => :define do
|
|||
end
|
||||
|
||||
describe "when using default parameters" do
|
||||
let :params do
|
||||
default_params
|
||||
end
|
||||
it { should contain_exec("/usr/bin/apt-get -y install #{title}").with(
|
||||
:unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'",
|
||||
:logoutput => 'on_failure',
|
||||
:timeout => '300'
|
||||
) }
|
||||
end
|
||||
|
|
|
@ -18,13 +18,6 @@ describe 'apt::hold' do
|
|||
let :params do default_params end
|
||||
|
||||
it 'creates an apt preferences file' do
|
||||
should contain_apt__hold(title).with({
|
||||
:ensure => 'present',
|
||||
:package => title,
|
||||
:version => params[:version],
|
||||
:priority => 1001,
|
||||
})
|
||||
|
||||
should contain_apt__pin("hold_#{title}").with({
|
||||
:ensure => 'present',
|
||||
:packages => title,
|
||||
|
@ -38,9 +31,6 @@ describe 'apt::hold' do
|
|||
let :params do default_params.merge({:ensure => 'absent',}) end
|
||||
|
||||
it 'creates an apt preferences file' do
|
||||
should contain_apt__hold(title).with({
|
||||
:ensure => params[:ensure],
|
||||
})
|
||||
|
||||
should contain_apt__pin("hold_#{title}").with({
|
||||
:ensure => params[:ensure],
|
||||
|
@ -52,13 +42,6 @@ describe 'apt::hold' do
|
|||
let :params do default_params.merge({:priority => 990,}) end
|
||||
|
||||
it 'creates an apt preferences file' do
|
||||
should contain_apt__hold(title).with({
|
||||
:ensure => 'present',
|
||||
:package => title,
|
||||
:version => params[:version],
|
||||
:priority => params[:priority],
|
||||
})
|
||||
|
||||
should contain_apt__pin("hold_#{title}").with({
|
||||
:ensure => 'present',
|
||||
:packages => title,
|
||||
|
@ -68,6 +51,20 @@ describe 'apt::hold' do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'package => foo' do
|
||||
let :params do default_params.merge({:package => 'foo'}) end
|
||||
|
||||
it 'creates an apt preferences file' do
|
||||
should contain_apt__pin("hold_foo").with({
|
||||
:ensure => 'present',
|
||||
:packages => 'foo',
|
||||
:version => params[:version],
|
||||
:priority => 1001,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe 'validation' do
|
||||
context 'version => {}' do
|
||||
let :params do { :version => {}, } end
|
||||
|
|
|
@ -10,12 +10,6 @@ describe 'apt::key', :type => :define do
|
|||
|
||||
describe 'normal operation' do
|
||||
describe 'default options' do
|
||||
it 'contains the apt::key' do
|
||||
should contain_apt__key(title).with({
|
||||
:key => title,
|
||||
:ensure => 'present',
|
||||
})
|
||||
end
|
||||
it 'contains the apt_key' do
|
||||
should contain_apt_key(title).with({
|
||||
:id => title,
|
||||
|
@ -40,12 +34,6 @@ describe 'apt::key', :type => :define do
|
|||
:key => GPG_KEY_ID,
|
||||
} end
|
||||
|
||||
it 'contains the apt::key' do
|
||||
should contain_apt__key(title).with({
|
||||
:key => GPG_KEY_ID,
|
||||
:ensure => 'present',
|
||||
})
|
||||
end
|
||||
it 'contains the apt_key' do
|
||||
should contain_apt_key(title).with({
|
||||
:id => GPG_KEY_ID,
|
||||
|
@ -66,12 +54,6 @@ describe 'apt::key', :type => :define do
|
|||
:ensure => 'absent',
|
||||
} end
|
||||
|
||||
it 'contains the apt::key' do
|
||||
should contain_apt__key(title).with({
|
||||
:key => title,
|
||||
:ensure => 'absent',
|
||||
})
|
||||
end
|
||||
it 'contains the apt_key' do
|
||||
should contain_apt_key(title).with({
|
||||
:id => title,
|
||||
|
@ -87,81 +69,22 @@ describe 'apt::key', :type => :define do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'key_content =>' do
|
||||
describe 'set a bunch of things!' do
|
||||
let :params do {
|
||||
:key_content => 'GPG key content',
|
||||
} end
|
||||
|
||||
it 'contains the apt::key' do
|
||||
should contain_apt__key(title).with({
|
||||
:key => title,
|
||||
:ensure => 'present',
|
||||
:key_content => params[:key_content],
|
||||
})
|
||||
end
|
||||
it 'contains the apt_key' do
|
||||
should contain_apt_key(title).with({
|
||||
:id => title,
|
||||
:ensure => 'present',
|
||||
:source => nil,
|
||||
:server => nil,
|
||||
:content => params[:key_content],
|
||||
:keyserver_options => nil,
|
||||
})
|
||||
end
|
||||
it 'contains the apt_key present anchor' do
|
||||
should contain_anchor("apt_key #{title} present")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'key_source =>' do
|
||||
let :params do {
|
||||
:key_source => 'http://apt.puppetlabs.com/pubkey.gpg',
|
||||
:key_server => 'pgp.mit.edu',
|
||||
:key_options => 'debug',
|
||||
} end
|
||||
|
||||
it 'contains the apt::key' do
|
||||
should contain_apt__key(title).with({
|
||||
:key => title,
|
||||
:ensure => 'present',
|
||||
:key_source => params[:key_source],
|
||||
})
|
||||
end
|
||||
it 'contains the apt_key' do
|
||||
should contain_apt_key(title).with({
|
||||
:id => title,
|
||||
:ensure => 'present',
|
||||
:source => params[:key_source],
|
||||
:server => nil,
|
||||
:content => nil,
|
||||
:keyserver_options => nil,
|
||||
})
|
||||
end
|
||||
it 'contains the apt_key present anchor' do
|
||||
should contain_anchor("apt_key #{title} present")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'key_server =>' do
|
||||
context 'domain name' do
|
||||
let :params do {
|
||||
:key_server => 'pgp.mit.edu',
|
||||
} end
|
||||
|
||||
it 'contains the apt::key' do
|
||||
should contain_apt__key(title).with({
|
||||
:key => title,
|
||||
:ensure => 'present',
|
||||
:key_server => 'pgp.mit.edu',
|
||||
})
|
||||
end
|
||||
it 'contains the apt_key' do
|
||||
should contain_apt_key(title).with({
|
||||
:id => title,
|
||||
:ensure => 'present',
|
||||
:source => nil,
|
||||
:server => params[:key_server],
|
||||
:content => nil,
|
||||
:keyserver_options => nil,
|
||||
:source => 'http://apt.puppetlabs.com/pubkey.gpg',
|
||||
:server => 'pgp.mit.edu',
|
||||
:content => params[:key_content],
|
||||
:keyserver_options => 'debug',
|
||||
})
|
||||
end
|
||||
it 'contains the apt_key present anchor' do
|
||||
|
@ -173,15 +96,43 @@ describe 'apt::key', :type => :define do
|
|||
let(:params) do{
|
||||
:key_server => 'p-gp.m-it.edu',
|
||||
} end
|
||||
it "should contain apt::key" do
|
||||
should contain_apt__key(title).with({
|
||||
:key => title,
|
||||
:ensure => 'present',
|
||||
:key_server => 'p-gp.m-it.edu',
|
||||
it 'contains the apt_key' do
|
||||
should contain_apt_key(title).with({
|
||||
:id => title,
|
||||
:server => 'p-gp.m-it.edu',
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
context "url" do
|
||||
let :params do
|
||||
{
|
||||
:key_server => 'hkp://pgp.mit.edu',
|
||||
}
|
||||
end
|
||||
it 'contains the apt_key' do
|
||||
should contain_apt_key(title).with({
|
||||
:id => title,
|
||||
:server => 'hkp://pgp.mit.edu',
|
||||
})
|
||||
end
|
||||
end
|
||||
context "url with port number" do
|
||||
let :params do
|
||||
{
|
||||
:key_server => 'hkp://pgp.mit.edu:80',
|
||||
}
|
||||
end
|
||||
it 'contains the apt_key' do
|
||||
should contain_apt_key(title).with({
|
||||
:id => title,
|
||||
:server => 'hkp://pgp.mit.edu:80',
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'validation' do
|
||||
context "domain begin with dash" do
|
||||
let(:params) do{
|
||||
:key_server => '-pgp.mit.edu',
|
||||
|
@ -208,60 +159,52 @@ describe 'apt::key', :type => :define do
|
|||
expect { subject } .to raise_error(/does not match/)
|
||||
end
|
||||
end
|
||||
|
||||
context "url" do
|
||||
let (:params) do{
|
||||
:key_server => 'hkp://pgp.mit.edu',
|
||||
} end
|
||||
it "should contain apt::key" do
|
||||
should contain_apt__key(title).with({
|
||||
:key => title,
|
||||
:ensure => 'present',
|
||||
:key_server => 'hkp://pgp.mit.edu',
|
||||
})
|
||||
context "exceed character url" do
|
||||
let :params do
|
||||
{
|
||||
:key_server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu'
|
||||
}
|
||||
end
|
||||
it 'fails' do
|
||||
expect { subject }.to raise_error(/does not match/)
|
||||
end
|
||||
end
|
||||
context "url with port number" do
|
||||
let (:params) do{
|
||||
:key_server => 'hkp://pgp.mit.edu:80',
|
||||
} end
|
||||
it "should contain apt::key" do
|
||||
should contain_apt__key(title).with({
|
||||
:key => title,
|
||||
:ensure => 'present',
|
||||
:key_server => 'hkp://pgp.mit.edu:80',
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
context "incorrect port number url" do
|
||||
let (:params) do{
|
||||
let :params do
|
||||
{
|
||||
:key_server => 'hkp://pgp.mit.edu:8008080'
|
||||
} end
|
||||
}
|
||||
end
|
||||
it 'fails' do
|
||||
expect { subject }.to raise_error(/does not match/)
|
||||
end
|
||||
end
|
||||
context "incorrect protocol for url" do
|
||||
let (:params) do{
|
||||
let :params do
|
||||
{
|
||||
:key_server => 'abc://pgp.mit.edu:80'
|
||||
} end
|
||||
}
|
||||
end
|
||||
it 'fails' do
|
||||
expect { subject }.to raise_error(/does not match/)
|
||||
end
|
||||
end
|
||||
context "missing port number url" do
|
||||
let (:params) do{
|
||||
let :params do
|
||||
{
|
||||
:key_server => 'hkp://pgp.mit.edu:'
|
||||
} end
|
||||
}
|
||||
end
|
||||
it 'fails' do
|
||||
expect { subject }.to raise_error(/does not match/)
|
||||
end
|
||||
end
|
||||
context "url ending with a dot" do
|
||||
let (:params) do{
|
||||
let :params do
|
||||
{
|
||||
:key_server => 'hkp://pgp.mit.edu.'
|
||||
} end
|
||||
}
|
||||
end
|
||||
it 'fails' do
|
||||
expect { subject }.to raise_error(/does not match/)
|
||||
end
|
||||
|
@ -274,57 +217,6 @@ describe 'apt::key', :type => :define do
|
|||
expect { subject }.to raise_error(/does not match/)
|
||||
end
|
||||
end
|
||||
context "url with dash" do
|
||||
let(:params) do{
|
||||
:key_server => 'hkp://p-gp.m-it.edu',
|
||||
} end
|
||||
it "should contain apt::key" do
|
||||
should contain_apt__key(title).with({
|
||||
:key => title,
|
||||
:ensure => 'present',
|
||||
:key_server => 'hkp://p-gp.m-it.edu',
|
||||
})
|
||||
end
|
||||
end
|
||||
context "exceed characher url" do
|
||||
let (:params) do{
|
||||
:key_server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu'
|
||||
} end
|
||||
it 'fails' do
|
||||
expect { subject }.to raise_error(/does not match/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'key_options =>' do
|
||||
let :params do {
|
||||
:key_options => 'debug',
|
||||
} end
|
||||
|
||||
it 'contains the apt::key' do
|
||||
should contain_apt__key(title).with({
|
||||
:key => title,
|
||||
:ensure => 'present',
|
||||
:key_options => 'debug',
|
||||
})
|
||||
end
|
||||
it 'contains the apt_key' do
|
||||
should contain_apt_key(title).with({
|
||||
:id => title,
|
||||
:ensure => 'present',
|
||||
:source => nil,
|
||||
:server => nil,
|
||||
:content => nil,
|
||||
:keyserver_options => params[:key_options],
|
||||
})
|
||||
end
|
||||
it 'contains the apt_key present anchor' do
|
||||
should contain_anchor("apt_key #{title} present")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'validation' do
|
||||
context 'invalid key' do
|
||||
let :title do
|
||||
'Out of rum. Why? Why are we out of rum?'
|
||||
|
@ -369,6 +261,16 @@ describe 'apt::key', :type => :define do
|
|||
expect { subject }.to raise_error(/is not a string/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'invalid ensure' do
|
||||
let :params do
|
||||
{
|
||||
:ensure => 'foo',
|
||||
}
|
||||
end
|
||||
it 'fails' do
|
||||
expect { subject }.to raise_error(/does not match/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'duplication' do
|
||||
|
@ -411,3 +313,4 @@ describe 'apt::key', :type => :define do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,118 +3,165 @@ describe 'apt::pin', :type => :define do
|
|||
let(:facts) { { :lsbdistid => 'Debian' } }
|
||||
let(:title) { 'my_pin' }
|
||||
|
||||
let :default_params do
|
||||
{
|
||||
:ensure => 'present',
|
||||
:order => '',
|
||||
:packages => '*',
|
||||
:priority => '0',
|
||||
:release => nil
|
||||
}
|
||||
end
|
||||
|
||||
[
|
||||
{ :params => {},
|
||||
:content => "Explanation: : my_pin\nPackage: *\nPin: release a=my_pin\nPin-Priority: 0\n"
|
||||
},
|
||||
{
|
||||
:params => {
|
||||
:packages => 'apache',
|
||||
:priority => '1'
|
||||
},
|
||||
:content => "Explanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
|
||||
},
|
||||
{
|
||||
:params => {
|
||||
:order => 50,
|
||||
:packages => 'apache',
|
||||
:priority => '1'
|
||||
},
|
||||
:content => "Explanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
|
||||
},
|
||||
{
|
||||
:params => {
|
||||
:ensure => 'absent',
|
||||
:packages => 'apache',
|
||||
:priority => '1'
|
||||
},
|
||||
:content => "Explanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
|
||||
},
|
||||
{
|
||||
:params => {
|
||||
:packages => 'apache',
|
||||
:priority => '1',
|
||||
:release => 'my_newpin'
|
||||
},
|
||||
:content => "Explanation: : my_pin\nPackage: apache\nPin: release a=my_newpin\nPin-Priority: 1\n"
|
||||
},
|
||||
{
|
||||
:params => {
|
||||
:packages => 'apache',
|
||||
:priority => '1',
|
||||
:version => '2.2.16*'
|
||||
},
|
||||
:content => "Explanation: : my_pin\nPackage: apache\nPin: version 2.2.16*\nPin-Priority: 1\n"
|
||||
},
|
||||
{
|
||||
:params => {
|
||||
:priority => '1',
|
||||
:origin => 'ftp.de.debian.org'
|
||||
},
|
||||
:content => "Explanation: : my_pin\nPackage: *\nPin: origin ftp.de.debian.org\nPin-Priority: 1\n"
|
||||
},
|
||||
{
|
||||
:params => {
|
||||
:packages => 'apache',
|
||||
:priority => '1',
|
||||
:release => 'stable',
|
||||
:codename => 'wheezy',
|
||||
:release_version => '3.0',
|
||||
:component => 'main',
|
||||
:originator => 'Debian',
|
||||
:label => 'Debian'
|
||||
},
|
||||
:content => "Explanation: : my_pin\nPackage: apache\nPin: release a=stable, n=wheezy, v=3.0, c=main, o=Debian, l=Debian\nPin-Priority: 1\n"
|
||||
},
|
||||
{
|
||||
:params => {
|
||||
:packages => ['apache', 'ntop'],
|
||||
},
|
||||
:content => "Explanation: : my_pin\nPackage: apache ntop\nPin: release a=my_pin\nPin-Priority: 0\n"
|
||||
},
|
||||
].each do |param_set|
|
||||
describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
|
||||
let :param_hash do
|
||||
default_params.merge(param_set[:params])
|
||||
end
|
||||
|
||||
let :params do
|
||||
param_set[:params]
|
||||
end
|
||||
|
||||
it { should contain_class("apt::params") }
|
||||
|
||||
it { should contain_file("#{title}.pref").with({
|
||||
'ensure' => param_hash[:ensure],
|
||||
'path' => "/etc/apt/preferences.d/#{param_hash[:order] == '' ? "" : "#{param_hash[:order]}-"}#{title}.pref",
|
||||
context 'defaults' do
|
||||
it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: \*\nPin: release a=my_pin\nPin-Priority: 0\n/)}
|
||||
it { is_expected.to contain_file("my_pin.pref").with({
|
||||
'ensure' => 'present',
|
||||
'path' => '/etc/apt/preferences.d/my_pin.pref',
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'mode' => '0644',
|
||||
'content' => param_set[:content],
|
||||
})
|
||||
}
|
||||
end
|
||||
|
||||
context 'set version' do
|
||||
let :params do
|
||||
{
|
||||
'packages' => 'vim',
|
||||
'version' => '1',
|
||||
}
|
||||
end
|
||||
it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: vim\nPin: version 1\nPin-Priority: 0\n/)}
|
||||
it { is_expected.to contain_file("my_pin.pref").with({
|
||||
'ensure' => 'present',
|
||||
'path' => '/etc/apt/preferences.d/my_pin.pref',
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'mode' => '0644',
|
||||
})
|
||||
}
|
||||
end
|
||||
|
||||
describe 'resource title with invalid chars' do
|
||||
context 'spaces' do
|
||||
let(:title) { 'oh my god this is not valid' }
|
||||
it { should contain_file('oh_my_god_this_is_not_valid.pref') }
|
||||
context 'set origin' do
|
||||
let :params do
|
||||
{
|
||||
'packages' => 'vim',
|
||||
'origin' => 'test',
|
||||
}
|
||||
end
|
||||
it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: vim\nPin: origin test\nPin-Priority: 0\n/)}
|
||||
it { is_expected.to contain_file("my_pin.pref").with({
|
||||
'ensure' => 'present',
|
||||
'path' => '/etc/apt/preferences.d/my_pin.pref',
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'mode' => '0644',
|
||||
})
|
||||
}
|
||||
end
|
||||
|
||||
context '#$&*$' do
|
||||
let(:title) { 'so && many $* invalid @! things' }
|
||||
it { should contain_file('so____many____invalid____things.pref') }
|
||||
context 'not defaults' do
|
||||
let :params do
|
||||
{
|
||||
'explanation' => 'foo',
|
||||
'order' => 99,
|
||||
'release' => '1',
|
||||
'codename' => 'bar',
|
||||
'release_version' => '2',
|
||||
'component' => 'baz',
|
||||
'originator' => 'foobar',
|
||||
'label' => 'foobaz',
|
||||
'priority' => 10,
|
||||
}
|
||||
end
|
||||
it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: foo\nPackage: \*\nPin: release a=1, n=bar, v=2, c=baz, o=foobar, l=foobaz\nPin-Priority: 10\n/) }
|
||||
it { is_expected.to contain_file("my_pin.pref").with({
|
||||
'ensure' => 'present',
|
||||
'path' => '/etc/apt/preferences.d/99-my_pin.pref',
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'mode' => '0644',
|
||||
})
|
||||
}
|
||||
end
|
||||
|
||||
context 'ensure absent' do
|
||||
let :params do
|
||||
{
|
||||
'ensure' => 'absent'
|
||||
}
|
||||
end
|
||||
it { is_expected.to contain_file("my_pin.pref").with({
|
||||
'ensure' => 'absent',
|
||||
})
|
||||
}
|
||||
end
|
||||
|
||||
context 'bad characters' do
|
||||
let(:title) { 'such bad && wow!' }
|
||||
it { is_expected.to contain_file("such__bad____wow_.pref") }
|
||||
end
|
||||
|
||||
describe 'validation' do
|
||||
context 'invalid order' do
|
||||
let :params do
|
||||
{
|
||||
'order' => 'foo',
|
||||
}
|
||||
end
|
||||
it do
|
||||
expect {
|
||||
should compile
|
||||
}.to raise_error(Puppet::Error, /Only integers are allowed/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'packages == * and version' do
|
||||
let :params do
|
||||
{
|
||||
'version' => '1',
|
||||
}
|
||||
end
|
||||
it do
|
||||
expect {
|
||||
should compile
|
||||
}.to raise_error(Puppet::Error, /parameter version cannot be used in general form/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'packages == * and release and origin' do
|
||||
let :params do
|
||||
{
|
||||
'origin' => 'test',
|
||||
'release' => 'foo',
|
||||
}
|
||||
end
|
||||
it do
|
||||
expect {
|
||||
should compile
|
||||
}.to raise_error(Puppet::Error, /parameters release and origin are mutually exclusive/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'specific form with release and origin' do
|
||||
let :params do
|
||||
{
|
||||
'release' => 'foo',
|
||||
'origin' => 'test',
|
||||
'packages' => 'vim',
|
||||
}
|
||||
end
|
||||
it do
|
||||
expect {
|
||||
should compile
|
||||
}.to raise_error(Puppet::Error, /parameters release, origin, and version are mutually exclusive/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'specific form with version and origin' do
|
||||
let :params do
|
||||
{
|
||||
'version' => '1',
|
||||
'origin' => 'test',
|
||||
'packages' => 'vim',
|
||||
}
|
||||
end
|
||||
it do
|
||||
expect {
|
||||
should compile
|
||||
}.to raise_error(Puppet::Error, /parameters release, origin, and version are mutually exclusive/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,158 +1,163 @@
|
|||
require 'spec_helper'
|
||||
describe 'apt::ppa', :type => :define do
|
||||
[
|
||||
|
||||
describe 'defaults' do
|
||||
let :pre_condition do
|
||||
'class { "apt": }'
|
||||
end
|
||||
let :facts do
|
||||
{
|
||||
:lsbdistrelease => '11.04',
|
||||
:lsbdistcodename => 'natty',
|
||||
:operatingsystem => 'Ubuntu',
|
||||
:lsbdistid => 'Ubuntu',
|
||||
:package => 'python-software-properties'
|
||||
},
|
||||
{
|
||||
:lsbdistrelease => '12.10',
|
||||
:lsbdistcodename => 'quantal',
|
||||
:operatingsystem => 'Ubuntu',
|
||||
:lsbdistid => 'Ubuntu',
|
||||
:package => 'software-properties-common'
|
||||
},
|
||||
].each do |platform|
|
||||
context "on #{platform[:lsbdistcodename]}" do
|
||||
let :facts do
|
||||
{
|
||||
:lsbdistrelease => platform[:lsbdistrelease],
|
||||
:lsbdistcodename => platform[:lsbdistcodename],
|
||||
:operatingsystem => platform[:operatingsystem],
|
||||
:lsbdistid => platform[:lsbdistid],
|
||||
:osfamily => 'Debian',
|
||||
:lsbdistid => 'Ubuntu',
|
||||
}
|
||||
end
|
||||
let :release do
|
||||
"#{platform[:lsbdistcodename]}"
|
||||
|
||||
let(:title) { 'ppa:needs/such.substitution/wow' }
|
||||
it { is_expected.to contain_package('python-software-properties') }
|
||||
it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Exec[apt_update]').with({
|
||||
'environment' => [],
|
||||
'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow',
|
||||
'unless' => '/usr/bin/test -s /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list',
|
||||
'user' => 'root',
|
||||
'logoutput' => 'on_failure',
|
||||
})
|
||||
}
|
||||
|
||||
it { is_expected.to contain_file('/etc/apt/sources.list.d/needs-such_substitution-wow-natty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with({
|
||||
'ensure' => 'file',
|
||||
})
|
||||
}
|
||||
end
|
||||
let :package do
|
||||
"#{platform[:package]}"
|
||||
end
|
||||
let :options do
|
||||
"-y"
|
||||
end
|
||||
['ppa:dans_ppa', 'dans_ppa','ppa:dans-daily/ubuntu'].each do |t|
|
||||
describe "with title #{t}" do
|
||||
|
||||
describe 'apt included, no proxy' do
|
||||
let :pre_condition do
|
||||
'class { "apt": }'
|
||||
end
|
||||
let :title do
|
||||
t
|
||||
end
|
||||
let :filename do
|
||||
t.sub(/^ppa:/,'').gsub('/','-') << "-" << "#{release}.list"
|
||||
end
|
||||
|
||||
it { should contain_package("#{package}") }
|
||||
|
||||
it { should contain_exec("apt_update").with(
|
||||
'command' => '/usr/bin/apt-get update',
|
||||
'refreshonly' => true
|
||||
)
|
||||
}
|
||||
|
||||
it { should contain_exec("add-apt-repository-#{t}").with(
|
||||
'command' => "/usr/bin/add-apt-repository #{options} #{t}",
|
||||
'unless' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}",
|
||||
'require' => ["File[sources.list.d]", "Package[#{package}]"],
|
||||
'notify' => "Exec[apt_update]"
|
||||
)
|
||||
}
|
||||
|
||||
it { should create_file("/etc/apt/sources.list.d/#{filename}").with(
|
||||
'ensure' => 'file',
|
||||
'require' => "Exec[add-apt-repository-#{t}]"
|
||||
)
|
||||
}
|
||||
end
|
||||
end
|
||||
describe 'without a proxy defined' do
|
||||
let :title do
|
||||
'rspec_ppa'
|
||||
end
|
||||
let :pre_condition do
|
||||
'class { "apt":
|
||||
proxy_host => false
|
||||
}'
|
||||
end
|
||||
let :filename do
|
||||
"#{title}-#{release}.list"
|
||||
end
|
||||
|
||||
it { should contain_exec("add-apt-repository-#{title}").with(
|
||||
'environment' => [],
|
||||
'command' => "/usr/bin/add-apt-repository #{options} #{title}",
|
||||
'unless' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}",
|
||||
'require' => ["File[sources.list.d]", "Package[#{package}]"],
|
||||
'notify' => "Exec[apt_update]"
|
||||
)
|
||||
}
|
||||
end
|
||||
|
||||
describe 'behind a proxy' do
|
||||
let :title do
|
||||
'rspec_ppa'
|
||||
end
|
||||
let :pre_condition do
|
||||
'class { "apt":
|
||||
proxy_host => "user:pass@proxy",
|
||||
}'
|
||||
end
|
||||
let :filename do
|
||||
"#{title}-#{release}.list"
|
||||
end
|
||||
|
||||
it { should contain_exec("add-apt-repository-#{title}").with(
|
||||
'environment' => [
|
||||
"http_proxy=http://user:pass@proxy:8080",
|
||||
"https_proxy=http://user:pass@proxy:8080",
|
||||
],
|
||||
'command' => "/usr/bin/add-apt-repository #{options} #{title}",
|
||||
'unless' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}",
|
||||
'require' => ["File[sources.list.d]", "Package[#{package}]"],
|
||||
'notify' => "Exec[apt_update]"
|
||||
)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
[ { :lsbdistcodename => 'natty',
|
||||
:package => 'python-software-properties' },
|
||||
{ :lsbdistcodename => 'quantal',
|
||||
:package => 'software-properties-common'},
|
||||
].each do |platform|
|
||||
context "on #{platform[:lsbdistcodename]}" do
|
||||
describe "it should not error if package['#{platform[:package]}'] is already defined" do
|
||||
let :pre_condition do
|
||||
'class {"apt": }' +
|
||||
'package { "#{platform[:package]}": }->Apt::Ppa["ppa"]'
|
||||
end
|
||||
let :facts do
|
||||
{:lsbdistcodename => '#{platform[:lsbdistcodename]}',
|
||||
{
|
||||
:lsbdistrelease => '14.04',
|
||||
:lsbdistcodename => 'trusty',
|
||||
:operatingsystem => 'Ubuntu',
|
||||
:lsbdistid => 'Ubuntu',
|
||||
:osfamily => 'Debian'}
|
||||
:osfamily => 'Debian',
|
||||
}
|
||||
end
|
||||
let(:title) { "ppa" }
|
||||
let(:release) { "#{platform[:lsbdistcodename]}" }
|
||||
it { should contain_package('#{platform[:package]}') }
|
||||
let :params do
|
||||
{
|
||||
'options' => '',
|
||||
}
|
||||
end
|
||||
let(:title) { 'ppa:foo' }
|
||||
it { is_expected.to contain_package('software-properties-common') }
|
||||
it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({
|
||||
'environment' => [],
|
||||
'command' => '/usr/bin/add-apt-repository ppa:foo',
|
||||
'unless' => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
|
||||
'user' => 'root',
|
||||
'logoutput' => 'on_failure',
|
||||
})
|
||||
}
|
||||
|
||||
it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_requires('Exec[add-apt-repository-ppa:foo]').with({
|
||||
'ensure' => 'file',
|
||||
})
|
||||
}
|
||||
end
|
||||
|
||||
describe 'apt included, proxy' do
|
||||
let :pre_condition do
|
||||
'class { "apt": proxy_host => "example.com" }'
|
||||
end
|
||||
let :facts do
|
||||
{
|
||||
:lsbdistrelease => '14.04',
|
||||
:lsbdistcodename => 'trusty',
|
||||
:operatingsystem => 'Ubuntu',
|
||||
:lsbdistid => 'Ubuntu',
|
||||
:osfamily => 'Debian',
|
||||
}
|
||||
end
|
||||
let :params do
|
||||
{
|
||||
'release' => 'lucid',
|
||||
}
|
||||
end
|
||||
let(:title) { 'ppa:foo' }
|
||||
it { is_expected.to contain_package('software-properties-common') }
|
||||
it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({
|
||||
'environment' => ['http_proxy=http://example.com:8080', 'https_proxy=http://example.com:8080'],
|
||||
'command' => '/usr/bin/add-apt-repository -y ppa:foo',
|
||||
'unless' => '/usr/bin/test -s /etc/apt/sources.list.d/foo-lucid.list',
|
||||
'user' => 'root',
|
||||
'logoutput' => 'on_failure',
|
||||
})
|
||||
}
|
||||
|
||||
it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-lucid.list').that_requires('Exec[add-apt-repository-ppa:foo]').with({
|
||||
'ensure' => 'file',
|
||||
})
|
||||
}
|
||||
end
|
||||
|
||||
describe 'ensure absent' do
|
||||
let :facts do
|
||||
{
|
||||
:lsbdistrelease => '14.04',
|
||||
:lsbdistcodename => 'trusty',
|
||||
:operatingsystem => 'Ubuntu',
|
||||
:lsbdistid => 'Ubuntu',
|
||||
:osfamily => 'Debian',
|
||||
}
|
||||
end
|
||||
let(:title) { 'ppa:foo' }
|
||||
let :params do
|
||||
{
|
||||
'ensure' => 'absent'
|
||||
}
|
||||
end
|
||||
it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_notifies('Exec[apt_update]').with({
|
||||
'ensure' => 'absent',
|
||||
})
|
||||
}
|
||||
end
|
||||
|
||||
context 'validation' do
|
||||
describe 'no release' do
|
||||
let :facts do
|
||||
{
|
||||
:lsbdistrelease => '14.04',
|
||||
:operatingsystem => 'Ubuntu',
|
||||
:lsbdistid => 'Ubuntu',
|
||||
:osfamily => 'Debian',
|
||||
}
|
||||
end
|
||||
let(:title) { 'ppa:foo' }
|
||||
it do
|
||||
expect {
|
||||
should compile
|
||||
}.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
|
||||
end
|
||||
end
|
||||
|
||||
describe "without Class[apt] should raise a Puppet::Error" do
|
||||
let(:release) { "natty" }
|
||||
let(:title) { "ppa" }
|
||||
it { expect { should contain_apt__ppa(title) }.to raise_error(Puppet::Error) }
|
||||
describe 'not ubuntu' do
|
||||
let :facts do
|
||||
{
|
||||
:lsbdistrelease => '14.04',
|
||||
:lsbdistcodename => 'trusty',
|
||||
:operatingsystem => 'Debian',
|
||||
:lsbdistid => 'Ubuntu',
|
||||
:osfamily => 'Debian',
|
||||
}
|
||||
end
|
||||
let(:title) { 'ppa:foo' }
|
||||
it do
|
||||
expect {
|
||||
should compile
|
||||
}.to raise_error(Puppet::Error, /apt::ppa is currently supported on Ubuntu only./)
|
||||
end
|
||||
end
|
||||
|
||||
describe "without release should raise a Puppet::Error" do
|
||||
let(:title) { "ppa:" }
|
||||
it { expect { should contain_apt__ppa(:release) }.to raise_error(Puppet::Error) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,179 +1,127 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'apt::source', :type => :define do
|
||||
let(:facts) { { :lsbdistid => 'Debian' } }
|
||||
GPG_KEY_ID = '4BD6EC30'
|
||||
|
||||
let :title do
|
||||
'my_source'
|
||||
end
|
||||
|
||||
let :default_params do
|
||||
{
|
||||
:ensure => 'present',
|
||||
:location => '',
|
||||
:release => 'karmic',
|
||||
:repos => 'main',
|
||||
:include_src => true,
|
||||
:include_deb => true,
|
||||
:required_packages => false,
|
||||
:key => false,
|
||||
:key_server => false,
|
||||
:key_content => false,
|
||||
:key_source => false,
|
||||
:pin => false
|
||||
}
|
||||
end
|
||||
|
||||
[{},
|
||||
{
|
||||
:location => 'http://example.com',
|
||||
:release => 'precise',
|
||||
:repos => 'security',
|
||||
:include_src => false,
|
||||
:required_packages => 'apache',
|
||||
:key => GPG_KEY_ID,
|
||||
:key_server => 'keyserver.debian.com',
|
||||
:pin => '600',
|
||||
:key_content => 'ABCD1234'
|
||||
},
|
||||
{
|
||||
:key => GPG_KEY_ID,
|
||||
:key_server => 'keyserver.debian.com',
|
||||
},
|
||||
{
|
||||
:ensure => 'absent',
|
||||
:location => 'http://example.com',
|
||||
:release => 'precise',
|
||||
:repos => 'security',
|
||||
},
|
||||
{
|
||||
:release => '',
|
||||
},
|
||||
{
|
||||
:release => 'custom',
|
||||
},
|
||||
{
|
||||
:architecture => 'amd64',
|
||||
}
|
||||
].each do |param_set|
|
||||
describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
|
||||
let :param_hash do
|
||||
default_params.merge(param_set)
|
||||
end
|
||||
|
||||
context 'mostly defaults' do
|
||||
let :facts do
|
||||
{:lsbdistcodename => 'karmic', :lsbdistid => 'Ubuntu'}
|
||||
{
|
||||
:lsbdistid => 'Debian',
|
||||
:lsbdistcodename => 'wheezy',
|
||||
}
|
||||
end
|
||||
|
||||
let :params do
|
||||
param_set
|
||||
{
|
||||
'include_deb' => false,
|
||||
}
|
||||
end
|
||||
|
||||
let :filename do
|
||||
"/etc/apt/sources.list.d/#{title}.list"
|
||||
end
|
||||
|
||||
let :content do
|
||||
content = "#file generated by puppet\n"
|
||||
if param_hash[:comment]
|
||||
content << "# #{comment}"
|
||||
else
|
||||
content << "# #{title}"
|
||||
end
|
||||
if param_hash[:architecture]
|
||||
arch = "[arch=#{param_hash[:architecture]}] "
|
||||
end
|
||||
if param_hash[:include_deb]
|
||||
content << "\ndeb #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
|
||||
end
|
||||
if param_hash[:include_src]
|
||||
content << "deb-src #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
|
||||
end
|
||||
content
|
||||
end
|
||||
|
||||
it { should contain_apt__params }
|
||||
|
||||
it { should contain_file("#{title}.list").with({
|
||||
'ensure' => param_hash[:ensure],
|
||||
'path' => filename,
|
||||
it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
|
||||
'ensure' => 'present',
|
||||
'path' => '/etc/apt/sources.list.d/my_source.list',
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'mode' => '0644',
|
||||
'content' => content,
|
||||
}).with_content(/#file generated by puppet\n# my_source\ndeb-src wheezy main\n/)
|
||||
}
|
||||
end
|
||||
|
||||
context 'no defaults' do
|
||||
let :facts do
|
||||
{
|
||||
:lsbdistid => 'Debian',
|
||||
:lsbdistcodename => 'wheezy',
|
||||
}
|
||||
end
|
||||
let :params do
|
||||
{
|
||||
'comment' => 'foo',
|
||||
'location' => 'http://debian.mirror.iweb.ca/debian/',
|
||||
'release' => 'sid',
|
||||
'repos' => 'testing',
|
||||
'include_src' => false,
|
||||
'required_packages' => 'vim',
|
||||
'key' => GPG_KEY_ID,
|
||||
'key_server' => 'pgp.mit.edu',
|
||||
'key_content' => 'GPG key content',
|
||||
'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
|
||||
'pin' => '10',
|
||||
'architecture' => 'x86_64',
|
||||
}
|
||||
end
|
||||
|
||||
it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
|
||||
'ensure' => 'present',
|
||||
'path' => '/etc/apt/sources.list.d/my_source.list',
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'mode' => '0644',
|
||||
}).with_content(/#file generated by puppet\n# foo\ndeb \[arch=x86_64\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
|
||||
}
|
||||
|
||||
it { is_expected.to contain_apt__pin('my_source').that_comes_before('File[my_source.list]').with({
|
||||
'ensure' => 'present',
|
||||
'priority' => '10',
|
||||
'origin' => 'debian.mirror.iweb.ca',
|
||||
})
|
||||
}
|
||||
|
||||
it {
|
||||
if param_hash[:pin]
|
||||
should contain_apt__pin(title).with({
|
||||
"priority" => param_hash[:pin],
|
||||
"before" => "File[#{title}.list]"
|
||||
})
|
||||
else
|
||||
should_not contain_apt__pin(title).with({
|
||||
"priority" => param_hash[:pin],
|
||||
"before" => "File[#{title}.list]"
|
||||
})
|
||||
end
|
||||
}
|
||||
|
||||
it {
|
||||
should contain_exec("apt_update").with({
|
||||
"command" => "/usr/bin/apt-get update",
|
||||
"refreshonly" => true
|
||||
it { is_expected.to contain_exec("Required packages: 'vim' for my_source").that_comes_before('Exec[apt_update]').that_subscribes_to('File[my_source.list]').with({
|
||||
'command' => '/usr/bin/apt-get -y install vim',
|
||||
'logoutput' => 'on_failure',
|
||||
'refreshonly' => true,
|
||||
'tries' => '3',
|
||||
'try_sleep' => '1',
|
||||
})
|
||||
}
|
||||
|
||||
it {
|
||||
if param_hash[:required_packages]
|
||||
should contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
|
||||
"command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
|
||||
"subscribe" => "File[#{title}.list]",
|
||||
"refreshonly" => true,
|
||||
"before" => 'Exec[apt_update]',
|
||||
it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('File[my_source.list]').with({
|
||||
'ensure' => 'present',
|
||||
'key' => GPG_KEY_ID,
|
||||
'key_server' => 'pgp.mit.edu',
|
||||
'key_content' => 'GPG key content',
|
||||
'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
|
||||
})
|
||||
else
|
||||
should_not contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
|
||||
"command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
|
||||
"subscribe" => "File[#{title}.list]",
|
||||
"refreshonly" => true
|
||||
})
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
it {
|
||||
key_server = param_hash[:key_server] || nil
|
||||
key_content = param_hash[:key_content] || nil
|
||||
key_source = param_hash[:key_source] || nil
|
||||
if param_hash[:key]
|
||||
should contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
|
||||
"key" => param_hash[:key],
|
||||
"ensure" => :present,
|
||||
"key_server" => key_server,
|
||||
"key_content" => key_content,
|
||||
"key_source" => key_source,
|
||||
"before" => "File[#{title}.list]"
|
||||
})
|
||||
else
|
||||
should_not contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
|
||||
"key" => param_hash[:key],
|
||||
"ensure" => :present,
|
||||
"key_server" => param_hash[:key_server],
|
||||
"key_content" => param_hash[:key_content],
|
||||
"key_source" => param_hash[:key_source],
|
||||
"before" => "File[#{title}.list]"
|
||||
})
|
||||
end
|
||||
context 'ensure => absent' do
|
||||
let :facts do
|
||||
{
|
||||
:lsbdistid => 'Debian',
|
||||
:lsbdistcodename => 'wheezy',
|
||||
}
|
||||
end
|
||||
let :params do
|
||||
{
|
||||
'ensure' => 'absent',
|
||||
}
|
||||
end
|
||||
|
||||
it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
|
||||
'ensure' => 'absent'
|
||||
})
|
||||
}
|
||||
end
|
||||
|
||||
describe 'validation' do
|
||||
context 'no release' do
|
||||
let :facts do
|
||||
{
|
||||
:lsbdistid => 'Debian',
|
||||
}
|
||||
end
|
||||
|
||||
it do
|
||||
expect {
|
||||
should compile
|
||||
}.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
|
||||
end
|
||||
end
|
||||
describe "without release should raise a Puppet::Error" do
|
||||
let(:default_params) { Hash.new }
|
||||
let(:facts) { Hash.new }
|
||||
it { expect { should raise_error(Puppet::Error) } }
|
||||
let(:facts) { { :lsbdistcodename => 'lucid', :lsbdistid => 'Ubuntu' } }
|
||||
it { should contain_apt__source(title) }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue