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',
99 'required_packages' => 'debian-keyring debian-archive-keyring',
101 'key_server' => 'subkeys.pgp.net',
103 'include_src' => true
106 'location' => 'http://apt.puppetlabs.com',
109 'key_server' => 'pgp.mit.edu',
114 should contain_file('debian_unstable.list').with({
115 'ensure' => 'present',
116 'path' => '/etc/apt/sources.list.d/debian_unstable.list',
120 'notify' => 'Exec[apt_update]',
124 it { should contain_file('debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
125 it { should contain_file('debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
128 should contain_file('puppetlabs.list').with({
129 'ensure' => 'present',
130 'path' => '/etc/apt/sources.list.d/puppetlabs.list',
134 'notify' => 'Exec[apt_update]',
138 it { should contain_file('puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
139 it { should contain_file('puppetlabs.list').with_content(/^deb-src http:\/\/apt.puppetlabs.com precise main$/) }
142 describe 'failing tests' do
143 context 'bad purge_sources_list' do
146 'purge_sources_list' => 'foo'
152 }.to raise_error(Puppet::Error)
156 context 'bad purge_sources_list_d' do
159 'purge_sources_list_d' => 'foo'
165 }.to raise_error(Puppet::Error)
169 context 'bad purge_preferences' do
172 'purge_preferences' => 'foo'
178 }.to raise_error(Puppet::Error)
182 context 'bad purge_preferences_d' do
185 'purge_preferences_d' => 'foo'
191 }.to raise_error(Puppet::Error)
195 context 'with unsupported osfamily' do
197 { :osfamily => 'Darwin', }
203 }.to raise_error(Puppet::Error, /This module only works on Debian or derivatives like Ubuntu/)