2 describe 'apt', :type => :class do
3 let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
6 it { should contain_file('sources.list').that_notifies('Exec[apt_update]').only_with({
8 'path' => '/etc/apt/sources.list',
12 'notify' => 'Exec[apt_update]',
15 it { should 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 { should 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 should 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 { should 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 { should contain_file('sources.list').with({
61 'content' => "# Repos managed by puppet.\n"
64 it { should contain_file('sources.list.d').with({
69 it { should contain_file('apt-preferences').only_with({
71 'path' => '/etc/apt/preferences',
74 it { should contain_file('preferences.d').with({
79 it { should 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 should contain_file('debian_unstable.list').with({
114 'ensure' => 'present',
115 'path' => '/etc/apt/sources.list.d/debian_unstable.list',
119 'notify' => 'Exec[apt_update]',
123 it { should contain_file('debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
124 it { should contain_file('debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
127 should contain_file('puppetlabs.list').with({
128 'ensure' => 'present',
129 'path' => '/etc/apt/sources.list.d/puppetlabs.list',
133 'notify' => 'Exec[apt_update]',
137 it { should contain_file('puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
140 describe 'failing tests' do
141 context 'bad purge_sources_list' do
144 'purge_sources_list' => 'foo'
150 }.to raise_error(Puppet::Error)
154 context 'bad purge_sources_list_d' do
157 'purge_sources_list_d' => 'foo'
163 }.to raise_error(Puppet::Error)
167 context 'bad purge_preferences' do
170 'purge_preferences' => 'foo'
176 }.to raise_error(Puppet::Error)
180 context 'bad purge_preferences_d' do
183 'purge_preferences_d' => 'foo'
189 }.to raise_error(Puppet::Error)
193 context 'with unsupported osfamily' do
195 { :osfamily => 'Darwin', }
201 }.to raise_error(Puppet::Error, /This module only works on Debian or derivatives like Ubuntu/)