Merge pull request #640 from ocadotechnology/dpkg_admin_lock
[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'                         => 1406660561,
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) { {
13           :os                      => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
14           :lsbdistid               => 'Debian',
15           :osfamily                => 'Debian',
16           :apt_update_last_success => factval,
17           :lsbdistcodename         => 'wheezy',
18           :puppetversion           => Puppet.version,
19         } }
20         let (:pre_condition) {
21           "class{'::apt': update => {'frequency' => 'always' },}"
22         }
23         it 'should trigger an apt-get update run' do
24           #set the apt_update exec's refreshonly attribute to false
25           is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
26         end
27       end
28     end
29     context 'when $::apt_update_last_success is nil' do
30       let(:facts) { {
31         :os              => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
32         :lsbdistid       => 'Debian',
33         :osfamily        => 'Debian',
34         :lsbdistcodename => 'wheezy',
35         :puppetversion   => Puppet.version,
36       } }
37       let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'always' },}" }
38       it 'should trigger an apt-get update run' do
39         #set the apt_update exec\'s refreshonly attribute to false
40         is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
41       end
42     end
43   end
44   context "and apt::update['frequency']='reluctantly'" do
45     {
46       'a recent run'                                 => Time.now.to_i,
47       'we are due for a run'                         => 1406660561,
48       'the update-success-stamp file does not exist' => -1,
49     }.each_pair do |desc, factval|
50       context "and $::apt_update_last_success indicates #{desc}" do
51         let(:facts) { {
52           :os                      => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
53           :lsbdistid               => 'Debian',
54           :osfamily                => 'Debian',
55           :apt_update_last_success => factval,
56           :lsbdistcodename         => 'wheezy',
57           :puppetversion           => Puppet.version,
58         } }
59         let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }
60         it 'should not trigger an apt-get update run' do
61           #don't change the apt_update exec's refreshonly attribute. (it should be true)
62           is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
63         end
64       end
65     end
66     context 'when $::apt_update_last_success is nil' do
67       let(:facts) { {
68         :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
69         :lsbdistid       => 'Debian',
70         :osfamily        => 'Debian',
71         :lsbdistcodename => 'wheezy',
72         :puppetversion   => Puppet.version,
73       } }
74       let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }
75       it 'should not trigger an apt-get update run' do
76         #don't change the apt_update exec's refreshonly attribute. (it should be true)
77         is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
78       end
79     end
80   end
81   ['daily','weekly'].each do |update_frequency|
82     context "and apt::update['frequency'] has the value of #{update_frequency}" do
83       { 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
84         context "and $::apt_update_last_success indicates #{desc}" do
85           let(:facts) { {
86             :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
87             :lsbdistid               => 'Debian',
88             :osfamily                => 'Debian',
89             :apt_update_last_success => factval,
90             :lsbdistcodename         => 'wheezy',
91             :puppetversion           => Puppet.version,
92           } }
93           let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
94           it 'should trigger an apt-get update run' do
95             #set the apt_update exec\'s refreshonly attribute to false
96             is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
97           end
98         end
99       end
100       context 'when the $::apt_update_last_success fact has a recent value' do
101         let(:facts) { {
102           :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
103           :lsbdistid               => 'Debian',
104           :osfamily                => 'Debian',
105           :lsbdistcodename         => 'wheezy',
106           :apt_update_last_success => Time.now.to_i,
107           :puppetversion           => Puppet.version,
108         } }
109         let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
110         it 'should not trigger an apt-get update run' do
111           #don't change the apt_update exec\'s refreshonly attribute. (it should be true)
112           is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
113         end
114       end
115       context 'when $::apt_update_last_success is nil' do
116         let(:facts) { {
117           :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
118           :lsbdistid               => 'Debian',
119           :osfamily                => 'Debian',
120           :lsbdistcodename         => 'wheezy',
121           :apt_update_last_success => nil,
122           :puppetversion           => Puppet.version,
123         } }
124         let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
125         it 'should trigger an apt-get update run' do
126           #set the apt_update exec\'s refreshonly attribute to false
127           is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
128         end
129       end
130     end
131   end
132 end