apt: Fix all strict variable cases.
[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 "when update['always']=true" do
6     #This should completely disable all of this logic. These tests are to guarantee that we don't somehow magically change the behavior.
7     let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
8     let (:pre_condition) { "class{'::apt': update => {'always' => true},}" }
9     it 'should trigger an apt-get update run' do
10       #set the apt_update exec's refreshonly attribute to false
11       is_expected.to contain_exec('apt_update').with({'refreshonly' => false })
12     end
13     ['always','daily','weekly','reluctantly'].each do |update_frequency|
14       context "when apt::update['frequency'] has the value of #{update_frequency}" do
15         { 'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
16           context "and $::apt_update_last_success indicates #{desc}" do
17             let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy' } }
18             let (:pre_condition) { "class{'::apt': update => {'always' => true, 'frequency' => '#{update_frequency}'}, }" }
19             it 'should trigger an apt-get update run' do
20               # set the apt_update exec's refreshonly attribute to false
21               is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
22             end
23           end
24           context 'when $::apt_update_last_success is nil' do
25             let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
26             let (:pre_condition) { "class{'::apt': update => {'always' => true, 'frequency' => '#{update_frequency}'}, }" }
27             it 'should trigger an apt-get update run' do
28               #set the apt_update exec\'s refreshonly attribute to false
29               is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
30             end
31           end
32         end
33       end
34     end
35   end
36
37   context "when apt::update['always']=false" do
38     context "and apt::update['frequency']='always'" do
39       { 'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
40         context "and $::apt_update_last_success indicates #{desc}" do
41           let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy' } }
42           let (:pre_condition) { "class{'::apt': update => {'always' => false, 'frequency' => 'always' },}" }
43           it 'should trigger an apt-get update run' do
44             #set the apt_update exec's refreshonly attribute to false
45             is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
46           end
47         end
48       end
49       context 'when $::apt_update_last_success is nil' do
50         let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
51         let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => 'always' },}" }
52         it 'should trigger an apt-get update run' do
53           #set the apt_update exec\'s refreshonly attribute to false
54           is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
55         end
56       end
57     end
58     context "and apt::update['frequency']='reluctantly'" do
59       {'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
60         context "and $::apt_update_last_success indicates #{desc}" do
61           let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy'} }
62           let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => 'reluctantly' },}" }
63           it 'should not trigger an apt-get update run' do
64             #don't change the apt_update exec's refreshonly attribute. (it should be true)
65             is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
66           end
67         end
68       end
69       context 'when $::apt_update_last_success is nil' do
70         let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
71         let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => 'reluctantly' },}" }
72         it 'should not trigger an apt-get update run' do
73           #don't change the apt_update exec's refreshonly attribute. (it should be true)
74           is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
75         end
76       end
77     end
78     ['daily','weekly'].each do |update_frequency|
79       context "and apt::update['frequency'] has the value of #{update_frequency}" do
80         { 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
81           context "and $::apt_update_last_success indicates #{desc}" do
82             let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy' } }
83             let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => '#{update_frequency}',} }" }
84             it 'should trigger an apt-get update run' do
85               #set the apt_update exec\'s refreshonly attribute to false
86               is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
87             end
88           end
89         end
90         context 'when the $::apt_update_last_success fact has a recent value' do
91           let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => Time.now.to_i } }
92             let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => '#{update_frequency}',} }" }
93           it 'should not trigger an apt-get update run' do
94             #don't change the apt_update exec\'s refreshonly attribute. (it should be true)
95             is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
96           end
97         end
98         context 'when $::apt_update_last_success is nil' do
99           let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => nil } }
100             let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => '#{update_frequency}',} }" }
101           it 'should trigger an apt-get update run' do
102             #set the apt_update exec\'s refreshonly attribute to false
103             is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
104           end
105         end
106       end
107     end
108   end
109 end