Merge pull request #710 from TMGMedia/circular-dep-fix
[puppet-modules/puppetlabs-apt.git] / spec / classes / apt_update_spec.rb
1 #!/usr/bin/env rspec
2 require 'spec_helper'
3
4 describe 'apt::update', type: :class do
5   context "and apt::update['frequency']='always'" do
6     {
7       'a recent run'                                 => Time.now.to_i,
8       'we are due for a run'                         => 1_406_660_561,
9       'the update-success-stamp file does not exist' => -1,
10     }.each_pair do |desc, factval|
11       context "and $::apt_update_last_success indicates #{desc}" do
12         let(:facts) do
13           {
14             os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
15             lsbdistid: 'Debian',
16             osfamily: 'Debian',
17             apt_update_last_success: factval,
18             lsbdistcodename: 'wheezy',
19             puppetversion: Puppet.version,
20           }
21         end
22         let (:pre_condition) do
23           "class{'::apt': update => {'frequency' => 'always' },}"
24         end
25
26         it 'triggers an apt-get update run' do
27           # set the apt_update exec's refreshonly attribute to false
28           is_expected.to contain_exec('apt_update').with('refreshonly' => false)
29         end
30       end
31     end
32     context 'when $::apt_update_last_success is nil' do
33       let(:facts) do
34         {
35           os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
36           lsbdistid: 'Debian',
37           osfamily: 'Debian',
38           lsbdistcodename: 'wheezy',
39           puppetversion: Puppet.version,
40         }
41       end
42       let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'always' },}" }
43
44       it 'triggers an apt-get update run' do
45         # set the apt_update exec\'s refreshonly attribute to false
46         is_expected.to contain_exec('apt_update').with('refreshonly' => false)
47       end
48     end
49   end
50   context "and apt::update['frequency']='reluctantly'" do
51     {
52       'a recent run'                                 => Time.now.to_i,
53       'we are due for a run'                         => 1_406_660_561,
54       'the update-success-stamp file does not exist' => -1,
55     }.each_pair do |desc, factval|
56       context "and $::apt_update_last_success indicates #{desc}" do
57         let(:facts) do
58           {
59             os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
60             lsbdistid: 'Debian',
61             osfamily: 'Debian',
62             apt_update_last_success: factval,
63             lsbdistcodename: 'wheezy',
64             puppetversion: Puppet.version,
65           }
66         end
67         let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }
68
69         it 'does not trigger an apt-get update run' do
70           # don't change the apt_update exec's refreshonly attribute. (it should be true)
71           is_expected.to contain_exec('apt_update').with('refreshonly' => true)
72         end
73       end
74     end
75     context 'when $::apt_update_last_success is nil' do
76       let(:facts) do
77         {
78           os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
79           lsbdistid: 'Debian',
80           osfamily: 'Debian',
81           lsbdistcodename: 'wheezy',
82           puppetversion: Puppet.version,
83         }
84       end
85       let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }
86
87       it 'does not trigger an apt-get update run' do
88         # don't change the apt_update exec's refreshonly attribute. (it should be true)
89         is_expected.to contain_exec('apt_update').with('refreshonly' => true)
90       end
91     end
92   end
93   %w[daily weekly].each do |update_frequency|
94     context "and apt::update['frequency'] has the value of #{update_frequency}" do
95       { 'we are due for a run' => 1_406_660_561, 'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
96         context "and $::apt_update_last_success indicates #{desc}" do
97           let(:facts) do
98             {
99               os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
100               lsbdistid: 'Debian',
101               osfamily: 'Debian',
102               apt_update_last_success: factval,
103               lsbdistcodename: 'wheezy',
104               puppetversion: Puppet.version,
105             }
106           end
107           let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
108
109           it 'triggers an apt-get update run' do
110             # set the apt_update exec\'s refreshonly attribute to false
111             is_expected.to contain_exec('apt_update').with('refreshonly' => false)
112           end
113         end
114       end
115       context 'when the $::apt_update_last_success fact has a recent value' do
116         let(:facts) do
117           {
118             os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
119             lsbdistid: 'Debian',
120             osfamily: 'Debian',
121             lsbdistcodename: 'wheezy',
122             apt_update_last_success: Time.now.to_i,
123             puppetversion: Puppet.version,
124           }
125         end
126         let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
127
128         it 'does not trigger an apt-get update run' do
129           # don't change the apt_update exec\'s refreshonly attribute. (it should be true)
130           is_expected.to contain_exec('apt_update').with('refreshonly' => true)
131         end
132       end
133       context 'when $::apt_update_last_success is nil' do
134         let(:facts) do
135           {
136             os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
137             lsbdistid: 'Debian',
138             osfamily: 'Debian',
139             lsbdistcodename: 'wheezy',
140             apt_update_last_success: nil,
141             puppetversion: Puppet.version,
142           }
143         end
144         let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
145
146         it 'triggers an apt-get update run' do
147           # set the apt_update exec\'s refreshonly attribute to false
148           is_expected.to contain_exec('apt_update').with('refreshonly' => false)
149         end
150       end
151     end
152   end
153 end