Skip to content

Commit

Permalink
Merge pull request #453 from puppetlabs/daenney/location-required
Browse files Browse the repository at this point in the history
apt::source: Make location required.
  • Loading branch information
Morgan Haskel committed Mar 6, 2015
2 parents a8250ae + 41a2725 commit 481846b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
6 changes: 5 additions & 1 deletion manifests/source.pp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# source.pp
# add an apt source
define apt::source(
$location = undef,
$comment = $name,
$ensure = present,
$location = '',
$release = $::apt::xfacts['lsbdistcodename'],
$repos = 'main',
$include = {},
Expand All @@ -20,6 +20,10 @@
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}"]
$_include = merge($::apt::include_defaults, $include)

Expand Down
44 changes: 32 additions & 12 deletions spec/defines/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,35 @@
end

context 'defaults' do
let :facts do
{
:lsbdistid => 'Debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian'
}
context 'without location' do
let :facts do
{
:lsbdistid => '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 wheezy main\n/)
}
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

describe 'no defaults' do
Expand Down Expand Up @@ -149,13 +166,14 @@
end
let :params do
{
:location => 'hello.there',
:allow_unsigned => true,
}
end

it { is_expected.to contain_apt__setting('list-my_source').with({
: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

Expand All @@ -169,14 +187,15 @@
end
let :params do
{
:location => 'hello.there',
:include => {'deb' => false, 'src' => true,},
:architecture => 'x86_64',
}
end

it { is_expected.to contain_apt__setting('list-my_source').with({
: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

Expand Down Expand Up @@ -208,6 +227,7 @@
:osfamily => 'Debian'
}
end
let(:params) { { :location => 'hello.there', } }

it do
expect {
Expand Down

0 comments on commit 481846b

Please sign in to comment.