1 # frozen_string_literal: true
5 describe 'apt::update', type: :class do
6 context "when apt::update['frequency']='always'" do
8 'a recent run' => Time.now.to_i,
9 'we are due for a run' => 1_406_660_561,
10 'the update-success-stamp file does not exist' => -1
11 }.each_pair do |desc, factval|
12 context "when $apt_update_last_success indicates #{desc}" do
27 apt_update_last_success: factval
30 let(:pre_condition) do
31 "class{'::apt': update => {'frequency' => 'always' },}"
34 it 'triggers an apt-get update run' do
35 # set the apt_update exec's refreshonly attribute to false
36 expect(subject).to contain_exec('apt_update').with('refreshonly' => false)
40 context 'when $apt_update_last_success is nil' do
57 let(:pre_condition) { "class{ '::apt': update => {'frequency' => 'always' },}" }
59 it 'triggers an apt-get update run' do
60 # set the apt_update exec\'s refreshonly attribute to false
61 expect(subject).to contain_exec('apt_update').with('refreshonly' => false)
65 context 'and Exec[apt_update] refreshonly is overridden to true and has recent run' do
80 apt_update_last_success: Time.now.to_i
83 let(:pre_condition) do
85 class{'::apt': update => {'frequency' => 'always' },}
86 Exec <| title=='apt_update' |> { refreshonly => true }
90 it 'skips an apt-get update run' do
91 # set the apt_update exec's refreshonly attribute to false
92 expect(subject).to contain_exec('apt_update').with('refreshonly' => true)
97 context "when apt::update['frequency']='reluctantly'" do
99 'a recent run' => Time.now.to_i,
100 'we are due for a run' => 1_406_660_561,
101 'the update-success-stamp file does not exist' => -1
102 }.each_pair do |desc, factval|
103 context "when $apt_update_last_success indicates #{desc}" do
118 apt_update_last_success: factval
121 let(:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }
123 it 'does not trigger an apt-get update run' do
124 # don't change the apt_update exec's refreshonly attribute. (it should be true)
125 expect(subject).to contain_exec('apt_update').with('refreshonly' => true)
129 context 'when $apt_update_last_success is nil' do
146 let(:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }
148 it 'does not trigger an apt-get update run' do
149 # don't change the apt_update exec's refreshonly attribute. (it should be true)
150 expect(subject).to contain_exec('apt_update').with('refreshonly' => true)
155 ['daily', 'weekly'].each do |update_frequency|
156 context "when apt::update['frequency'] has the value of #{update_frequency}" do
157 { 'we are due for a run' => 1_406_660_561, 'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
158 context "when $apt_update_last_success indicates #{desc}" do
173 apt_update_last_success: factval
176 let(:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
178 it 'triggers an apt-get update run' do
179 # set the apt_update exec\'s refreshonly attribute to false
180 expect(subject).to contain_exec('apt_update').with('refreshonly' => false)
184 context 'when the $apt_update_last_success fact has a recent value' do
199 apt_update_last_success: Time.now.to_i
202 let(:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
204 it 'does not trigger an apt-get update run' do
205 # don't change the apt_update exec\'s refreshonly attribute. (it should be true)
206 expect(subject).to contain_exec('apt_update').with('refreshonly' => true)
210 context 'when $apt_update_last_success is nil' do
225 apt_update_last_success: nil
228 let(:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
230 it 'triggers an apt-get update run' do
231 # set the apt_update exec\'s refreshonly attribute to false
232 expect(subject).to contain_exec('apt_update').with('refreshonly' => false)