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 contain_file('01proxy').that_notifies('Exec[apt_update]').only_with({
36 'path' => '/etc/apt/apt.conf.d/01proxy',
37 'notify' => 'Exec[apt_update]',
40 it 'should lay down /etc/apt/apt.conf.d/15update-stamp' do
41 should contain_file('/etc/apt/apt.conf.d/15update-stamp').with({
45 }).with_content(/APT::Update::Post-Invoke-Success \{"touch \/var\/lib\/apt\/periodic\/update-success-stamp 2>\/dev\/null \|\| true";\};/)
48 it { should contain_file('old-proxy-file').that_notifies('Exec[apt_update]').only_with({
50 'path' => '/etc/apt/apt.conf.d/proxy',
51 'notify' => 'Exec[apt_update]',
54 it { should contain_exec('apt_update').with({
55 'refreshonly' => 'true',
59 context 'lots of non-defaults' do
62 :always_apt_update => true,
63 :disable_keys => true,
65 :proxy_port => '9876',
66 :purge_sources_list => true,
67 :purge_sources_list_d => true,
68 :purge_preferences => true,
69 :purge_preferences_d => true,
70 :update_timeout => '1',
72 :fancy_progress => true,
76 it { should contain_file('sources.list').with({
77 'content' => "# Repos managed by puppet.\n"
80 it { should contain_file('sources.list.d').with({
85 it { should contain_file('apt-preferences').only_with({
87 'path' => '/etc/apt/preferences',
90 it { should contain_file('preferences.d').with({
95 it { should contain_file('99progressbar').only_with({
96 'ensure' => 'present',
97 'content' => /Dpkg::Progress-Fancy "1";/,
98 'path' => '/etc/apt/apt.conf.d/99progressbar',
101 it { should contain_file('99unauth').only_with({
102 'ensure' => 'present',
103 'content' => /APT::Get::AllowUnauthenticated 1;/,
104 'path' => '/etc/apt/apt.conf.d/99unauth',
107 it { should contain_file('01proxy').that_notifies('Exec[apt_update]').only_with({
108 'ensure' => 'present',
109 'path' => '/etc/apt/apt.conf.d/01proxy',
110 'content' => /Acquire::http::Proxy "http:\/\/foo:9876";/,
111 'notify' => 'Exec[apt_update]',
117 it { should contain_exec('apt_update').with({
118 'refreshonly' => 'false',
125 context 'more non-default' do
128 :fancy_progress => false,
129 :disable_keys => false,
133 it { should contain_file('99progressbar').only_with({
134 'ensure' => 'absent',
135 'path' => '/etc/apt/apt.conf.d/99progressbar',
138 it { should contain_file('99unauth').only_with({
139 'ensure' => 'absent',
140 'path' => '/etc/apt/apt.conf.d/99unauth',
145 context 'with sources defined on valid osfamily' do
147 { :osfamily => 'Debian',
148 :lsbdistcodename => 'precise',
149 :lsbdistid => 'Debian',
152 let(:params) { { :sources => {
153 'debian_unstable' => {
154 'location' => 'http://debian.mirror.iweb.ca/debian/',
155 'release' => 'unstable',
156 'repos' => 'main contrib non-free',
157 'required_packages' => 'debian-keyring debian-archive-keyring',
158 'key' => '150C8614919D8446E01E83AF9AA38DCD55BE302B',
159 'key_server' => 'subkeys.pgp.net',
161 'include_src' => true
164 'location' => 'http://apt.puppetlabs.com',
166 'key' => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30',
167 'key_server' => 'pgp.mit.edu',
172 should contain_file('debian_unstable.list').with({
173 'ensure' => 'present',
174 'path' => '/etc/apt/sources.list.d/debian_unstable.list',
178 'notify' => 'Exec[apt_update]',
182 it { should contain_file('debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
183 it { should contain_file('debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
186 should contain_file('puppetlabs.list').with({
187 'ensure' => 'present',
188 'path' => '/etc/apt/sources.list.d/puppetlabs.list',
192 'notify' => 'Exec[apt_update]',
196 it { should contain_file('puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
197 it { should contain_file('puppetlabs.list').with_content(/^deb-src http:\/\/apt.puppetlabs.com precise main$/) }
200 describe 'failing tests' do
201 context 'bad purge_sources_list' do
204 'purge_sources_list' => 'foo'
210 }.to raise_error(Puppet::Error)
214 context 'bad purge_sources_list_d' do
217 'purge_sources_list_d' => 'foo'
223 }.to raise_error(Puppet::Error)
227 context 'bad purge_preferences' do
230 'purge_preferences' => 'foo'
236 }.to raise_error(Puppet::Error)
240 context 'bad purge_preferences_d' do
243 'purge_preferences_d' => 'foo'
249 }.to raise_error(Puppet::Error)
253 context 'with unsupported osfamily' do
255 { :osfamily => 'Darwin', }
261 }.to raise_error(Puppet::Error, /This module only works on Debian or derivatives like Ubuntu/)