2 describe 'apt', :type => :class do
3 let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
6 it { is_expected.to contain_file('sources.list').that_notifies('Exec[apt_update]').only_with({
8 'path' => '/etc/apt/sources.list',
12 'notify' => 'Exec[apt_update]',
15 it { is_expected.to contain_file('sources.list.d').that_notifies('Exec[apt_update]').only_with({
16 'ensure' => 'directory',
17 'path' => '/etc/apt/sources.list.d',
22 'notify' => 'Exec[apt_update]',
25 it { is_expected.to contain_file('preferences.d').only_with({
26 'ensure' => 'directory',
27 'path' => '/etc/apt/preferences.d',
34 it 'should lay down /etc/apt/apt.conf.d/15update-stamp' do
35 is_expected.to contain_file('/etc/apt/apt.conf.d/15update-stamp').with({
39 }).with_content(/APT::Update::Post-Invoke-Success \{"touch \/var\/lib\/apt\/periodic\/update-success-stamp 2>\/dev\/null \|\| true";\};/)
42 it { is_expected.to contain_exec('apt_update').with({
43 'refreshonly' => 'true',
47 context 'lots of non-defaults' do
50 :always_apt_update => true,
51 :purge_sources_list => true,
52 :purge_sources_list_d => true,
53 :purge_preferences => true,
54 :purge_preferences_d => true,
55 :update_timeout => '1',
60 it { is_expected.to contain_file('sources.list').with({
61 'content' => "# Repos managed by puppet.\n"
64 it { is_expected.to contain_file('sources.list.d').with({
69 it { is_expected.to contain_file('apt-preferences').only_with({
71 'path' => '/etc/apt/preferences',
74 it { is_expected.to contain_file('preferences.d').with({
79 it { is_expected.to contain_exec('apt_update').with({
80 'refreshonly' => 'false',
87 context 'with sources defined on valid osfamily' do
89 { :osfamily => 'Debian',
90 :lsbdistcodename => 'precise',
91 :lsbdistid => 'Debian',
94 let(:params) { { :sources => {
95 'debian_unstable' => {
96 'location' => 'http://debian.mirror.iweb.ca/debian/',
97 'release' => 'unstable',
98 'repos' => 'main contrib non-free',
100 'key_server' => 'subkeys.pgp.net',
102 'include_src' => true
105 'location' => 'http://apt.puppetlabs.com',
108 'key_server' => 'pgp.mit.edu',
113 is_expected.to contain_apt__setting('debian_unstable').with({
114 'ensure' => 'present',
115 'notify' => 'Exec[apt_update]',
119 it { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
120 it { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
123 is_expected.to contain_apt__setting('puppetlabs').with({
124 'ensure' => 'present',
125 'notify' => 'Exec[apt_update]',
129 it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
132 describe 'failing tests' do
133 context 'bad purge_sources_list' do
136 'purge_sources_list' => 'foo'
141 is_expected.to compile
142 }.to raise_error(Puppet::Error)
146 context 'bad purge_sources_list_d' do
149 'purge_sources_list_d' => 'foo'
154 is_expected.to compile
155 }.to raise_error(Puppet::Error)
159 context 'bad purge_preferences' do
162 'purge_preferences' => 'foo'
167 is_expected.to compile
168 }.to raise_error(Puppet::Error)
172 context 'bad purge_preferences_d' do
175 'purge_preferences_d' => 'foo'
180 is_expected.to compile
181 }.to raise_error(Puppet::Error)
185 context 'with unsupported osfamily' do
187 { :osfamily => 'Darwin', }
192 is_expected.to compile
193 }.to raise_error(Puppet::Error, /This module only works on Debian or derivatives like Ubuntu/)