Merge pull request #706 from tphoney/rubocopification
[puppet-modules/puppetlabs-apt.git] / spec / acceptance / apt_spec.rb
1 require 'spec_helper_acceptance'
2
3 MAX_TIMEOUT_RETRY              = 3
4 TIMEOUT_RETRY_WAIT             = 5
5 TIMEOUT_ERROR_MATCHER = %r{no valid OpenPGP data found}
6
7 describe 'apt class' do
8   context 'reset' do
9     it 'fixes the sources.list' do
10       shell('cp /etc/apt/sources.list /tmp')
11     end
12   end
13
14   context 'all the things' do
15     it 'works with no errors' do
16       pp = <<-EOS
17       if $::lsbdistcodename == 'lucid' {
18         $sources = undef
19       } else {
20         $sources = {
21           'puppetlabs' => {
22             'ensure'   => present,
23             'location' => 'http://apt.puppetlabs.com',
24             'repos'    => 'main',
25             'key'      => {
26               'id'     => '6F6B15509CF8E59E6E469F327F438280EF8D349F',
27               'server' => 'hkps.pool.sks-keyservers.net',
28             },
29           },
30         }
31       }
32       class { 'apt':
33         update => {
34           'frequency' => 'always',
35           'timeout'   => 400,
36           'tries'     => 3,
37         },
38         purge => {
39           'sources.list'   => true,
40           'sources.list.d' => true,
41           'preferences'    => true,
42           'preferences.d'  => true,
43         },
44         sources => $sources,
45       }
46       EOS
47
48       # Apply the manifest (Retry if timeout error is received from key pool)
49       retry_on_error_matching(MAX_TIMEOUT_RETRY, TIMEOUT_RETRY_WAIT, TIMEOUT_ERROR_MATCHER) do
50         apply_manifest(pp, catch_failures: true)
51       end
52
53       apply_manifest(pp, catch_failures: true)
54     end
55     it 'stills work' do
56       shell('apt-get update')
57       shell('apt-get -y --force-yes upgrade')
58     end
59   end
60
61   context 'reset' do
62     it 'fixes the sources.list' do
63       shell('cp /tmp/sources.list /etc/apt')
64     end
65   end
66 end