Merge pull request #735 from pmcmaw/rubocop
[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 everything_everything_pp = <<-MANIFEST
8       if $::lsbdistcodename == 'lucid' {
9         $sources = undef
10       } else {
11         $sources = {
12           'puppetlabs' => {
13             'ensure'   => present,
14             'location' => 'http://apt.puppetlabs.com',
15             'repos'    => 'main',
16             'key'      => {
17               'id'     => '6F6B15509CF8E59E6E469F327F438280EF8D349F',
18               'server' => 'hkps.pool.sks-keyservers.net',
19             },
20           },
21         }
22       }
23       class { 'apt':
24         update => {
25           'frequency' => 'always',
26           'timeout'   => 400,
27           'tries'     => 3,
28         },
29         purge => {
30           'sources.list'   => true,
31           'sources.list.d' => true,
32           'preferences'    => true,
33           'preferences.d'  => true,
34         },
35         sources => $sources,
36       }
37   MANIFEST
38
39 describe 'apt class' do
40   context 'with reset' do
41     it 'fixes the sources.list' do
42       shell('cp /etc/apt/sources.list /tmp')
43     end
44   end
45
46   context 'with all the things' do
47     it 'works with no errors' do
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(everything_everything_pp, catch_failures: true)
51       end
52
53       apply_manifest(everything_everything_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 'with reset' do
62     it 'fixes the sources.list' do
63       shell('cp /tmp/sources.list /etc/apt')
64     end
65   end
66 end