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' } }
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 })
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 } }
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})
24 context 'when $::apt_update_last_success is nil' do
25 let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
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})
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 } }
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})
49 context 'when $::apt_update_last_success is nil' do
50 let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
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})
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} }
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})
69 context 'when $::apt_update_last_success is nil' do
70 let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
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})
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 } }
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})
90 context 'when the $::apt_update_last_success fact has a recent value' do
91 let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :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})
98 context 'when $::apt_update_last_success is nil' do
99 let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
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})