apt::source: Make location mostly required.

In what universe does it make sense to create a `sources.list.d` entry
for a repository **without** specifying where this repository is?
😖

😞 😩 😧 😱

Only when removing the resource should a location not be required.
This commit is contained in:
Daniele Sluijters 2015-03-05 20:35:02 +01:00
parent a8250aecfe
commit 41a2725683
2 changed files with 37 additions and 13 deletions

View file

@ -1,9 +1,9 @@
# source.pp # source.pp
# add an apt source # add an apt source
define apt::source( define apt::source(
$location = undef,
$comment = $name, $comment = $name,
$ensure = present, $ensure = present,
$location = '',
$release = $::apt::xfacts['lsbdistcodename'], $release = $::apt::xfacts['lsbdistcodename'],
$repos = 'main', $repos = 'main',
$include = {}, $include = {},
@ -20,6 +20,10 @@ define apt::source(
fail('lsbdistcodename fact not available: release parameter required') fail('lsbdistcodename fact not available: release parameter required')
} }
if $ensure == 'present' and ! $location {
fail('cannot create a source entry without specifying a location')
}
$_before = Apt::Setting["list-${title}"] $_before = Apt::Setting["list-${title}"]
$_include = merge($::apt::include_defaults, $include) $_include = merge($::apt::include_defaults, $include)

View file

@ -12,18 +12,35 @@ describe 'apt::source' do
end end
context 'defaults' do context 'defaults' do
let :facts do context 'without location' do
{ let :facts do
:lsbdistid => 'Debian', {
:lsbdistcodename => 'wheezy', :lsbdistid => 'Debian',
:osfamily => 'Debian' :lsbdistcodename => 'wheezy',
:osfamily => 'Debian'
}
end
it do
expect {
is_expected.to compile
}.to raise_error(Puppet::Error, /source entry without specifying a location/)
end
end
context 'with location' do
let :facts do
{
:lsbdistid => 'Debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian'
}
end
let(:params) { { :location => 'hello.there', } }
it { is_expected.to contain_apt__setting('list-my_source').with({
:ensure => 'present',
}).without_content(/# my_source\ndeb-src hello.there wheezy main\n/)
} }
end end
it { is_expected.to contain_apt__setting('list-my_source').with({
:ensure => 'present',
}).without_content(/# my_source\ndeb-src wheezy main\n/)
}
end end
describe 'no defaults' do describe 'no defaults' do
@ -149,13 +166,14 @@ describe 'apt::source' do
end end
let :params do let :params do
{ {
:location => 'hello.there',
:allow_unsigned => true, :allow_unsigned => true,
} }
end end
it { is_expected.to contain_apt__setting('list-my_source').with({ it { is_expected.to contain_apt__setting('list-my_source').with({
:ensure => 'present', :ensure => 'present',
}).with_content(/# my_source\ndeb \[trusted=yes\] wheezy main\n/) }).with_content(/# my_source\ndeb \[trusted=yes\] hello.there wheezy main\n/)
} }
end end
@ -169,6 +187,7 @@ describe 'apt::source' do
end end
let :params do let :params do
{ {
:location => 'hello.there',
:include => {'deb' => false, 'src' => true,}, :include => {'deb' => false, 'src' => true,},
:architecture => 'x86_64', :architecture => 'x86_64',
} }
@ -176,7 +195,7 @@ describe 'apt::source' do
it { is_expected.to contain_apt__setting('list-my_source').with({ it { is_expected.to contain_apt__setting('list-my_source').with({
:ensure => 'present', :ensure => 'present',
}).with_content(/# my_source\ndeb-src \[arch=x86_64 \] wheezy main\n/) }).with_content(/# my_source\ndeb-src \[arch=x86_64 \] hello.there wheezy main\n/)
} }
end end
@ -208,6 +227,7 @@ describe 'apt::source' do
:osfamily => 'Debian' :osfamily => 'Debian'
} }
end end
let(:params) { { :location => 'hello.there', } }
it do it do
expect { expect {